1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Grids;
type
TForm1 = class(TForm)
edit1: TEdit;
maGrille: TStringGrid;
procedure FormCreate(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
private
{ Déclarations privées }
public
{ Déclarations publiques }
i : integer;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
with maGrille do begin
RowCount := 2;
ColCount := 10;
end;
with edit1 do begin
MaxLength := 9;
NumbersOnly := True;
Text := '';
end;
i := 0;
end;
begin
if Length(edit1.Text) = 9 then begin
inc(i);
with maGrille do
if i < ColCount then begin
Cells[i, 1] := edit1.Text;
edit1.Text := '';
if i = ColCount -1 then begin
Key := #0; //->Pour ne pas valider le dernière caractère entré : à commenter pour tester
Showmessage('Remplissage terminé.');
edit1.Enabled := False;
end;
end;
end;
end;
{Autre factorisation du code possible
begin
if Length(Edit1.Text) = 9 then begin
inc(i);
with maGrille, Edit1 do
if i < ColCount then begin
Cells[i, 1] := Text;
Text := '';
if i = ColCount -1 then begin
Key := #0; //->Pour ne pas valider le dernière caractère entré : à commenter pour tester
Showmessage('Remplissage terminé.');
Enabled := False;
end;
end;
end;
end;
}
end. |
Partager