Ver Mensaje Individual
  #7  
Antiguo 19-08-2006
Avatar de MaMu
MaMu MaMu is offline
Miembro
 
Registrado: abr 2006
Ubicación: Argentina
Posts: 863
Reputación: 19
MaMu Va por buen camino
Un TEdit limitado para entrar números Enteros

Código:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
 var sNumAnterior:string;
 begin
   sNumAnterior := (sender as TEdit).Text;
   if (key <> #3) and (key <> #22) then  // #3 = Copiar (Ctrl + C)
   begin                                 // #22 = Pegar (Ctrl + V)
     if key = '-' then
     begin
       if ((pos(key,(sender as TEdit).Text) > 0) and
          (pos(key,(sender as TEdit).SelText) = 0))
          or
          ((sender as TEdit).SelStart > 0)
       then key:=#0;
     end
     else if not (key in ['0'..'9',#8]) then key:=#0;
   end;
   if key = #22 then
   try
     key := #0;
     (sender as TEdit).PasteFromClipBoard;
     StrToInt((sender as TEdit).Text);
   except
     (sender as TEdit).Text := sNumAnterior;
     (sender as TEdit).SelStart := Length((sender as TEdit).Text);
   end;
 end;

Un TEdit limitado para entrar números Reales

Código:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
 var sNumAnterior:string;
 begin
   sNumAnterior := (sender as TEdit).Text;
   if (key <> #3) and (key <> #22) then  // #3 = Copiar (Ctrl + C)
   begin                                 // #22 = Pegar (Ctrl + V)
     if key in ['-','.'] then
     begin
       if (pos(key,(sender as TEdit).Text) > 0) and
          (pos(key,(sender as TEdit).SelText) = 0)
          then key:=#0;
       case key of
         '-': if ((sender as TEdit).SelStart > 0) then key:=#0;
         '.': if ((sender as TEdit).SelStart = 0) or
                 (((sender as TEdit).SelStart = 1) and
                 ((sender as TEdit).Text[1] = '-'))
              then key:=#0;
       end;
     end
     else if not (key in ['0'..'9',#8]) then key:=#0;
   end;
   if key = #22 then
   try
     key := #0;
     (sender as TEdit).PasteFromClipBoard;
     StrToFloat((sender as TEdit).Text);
   except
     (sender as TEdit).Text := sNumAnterior;
     (sender as TEdit).SelStart := Length((sender as TEdit).Text);
   end;
 end;
by Arturo_Ortí

arturo98@santandersupernet.com
Responder Con Cita