Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   aceptar un solo punto en un StringGrid (https://www.clubdelphi.com/foros/showthread.php?t=43608)

Narvaez 16-05-2007 01:05:10

aceptar un solo punto en un StringGrid
 
Hola de nuevo, tengo un nuevo problema:
metí el siguiente codigo en un Tedit para que me aceptara numeros reales y un solo punto, me funciona correctamente pero quisiera saber como se le hace para que eso funcione en las celdas de un StringGrid.

Código Delphi [-]procedure TDatosCultivo.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
If not (Key in ['0'..'9','.',#8]) then Key:=#0;
If (Key='.') and (Pos('.',Edit2.Text)>0) Then Key:=#0;
end;

BuenaOnda 16-05-2007 06:41:45

Bueno utilizando el codigo que muestras..yo haria lo siguiente..

Código Delphi [-]
 
procedure TForm1.TuGrillaKeyPress(Sender: TObject; var Key: Char);
begin

    //Suponiendo que  "TuGrilla" posee 4 columnas...
      WITH TuGrilla DO
      BEGIN
           CASE Col OF
                1:BEGIN
                       If not (Key in ['0'..'9','.',#8]) then Key:=#0;
                       If (Key='.') and (Pos('.',Cells[Col,Row])>0) Then Key:=#0;
                  END;
                2:BEGIN
                       If not (Key in ['0'..'9','.',#8]) then Key:=#0;
                       If (Key='.') and (Pos('.',Cells[Col,Row])>0) Then Key:=#0;
                  END;
                3:BEGIN
                       If not (Key in ['0'..'9','.',#8]) then Key:=#0;
                       If (Key='.') and (Pos('.',Cells[Col,Row])>0) Then Key:=#0;
                  END;
                4:BEGIN
                       If not (Key in ['0'..'9','.',#8]) then Key:=#0;
                       If (Key='.') and (Pos('.',Cells[Col,Row])>0) Then Key:=#0;
                  END;
           END;
      END;
 
end;

espero que te sirva...


La franja horaria es GMT +2. Ahora son las 22:21:17.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi