Ver Mensaje Individual
  #3  
Antiguo 27-06-2007
Avatar de jhonny
jhonny jhonny is offline
Jhonny Suárez
 
Registrado: may 2003
Ubicación: Colombia
Posts: 7.058
Reputación: 30
jhonny Va camino a la famajhonny Va camino a la fama
Si me permites "pachotear" en cierta forma tu codigo, al final esta sería una versión funcional, que solo adapta lo anteriormente dicho por mi, pero a tu propio codigo :
Código Delphi [-]
 
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 ['-',DecimalSeparator] then
     begin
       if (pos(key,(sender as TEdit).Text) > 0) and
          (pos(key,(sender as TEdit).SelText) = 0)
          then key:=#0;
       if key ='-' then
       begin
         if ((sender as TEdit).SelStart > 0) then key:=#0;
       end
       else
       begin
         if key = DecimalSeparator then
         begin
           if ((sender as TEdit).SelStart = 0) or
                 (((sender as TEdit).SelStart = 1) and
                 ((sender as TEdit).Text[1] = '-'))
              then key:=#0;
         end;
       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;

Espero que esto te ayude.
__________________
Lecciones de mi Madre. Tema: modificación del comportamiento, "Pará de actuar como tu padre!"

http://www.purodelphi.com/
http://www.nosolodelphi.com/
Responder Con Cita