Bonjour,
Je pars de ceci :Je veux affecter à tous les TEdits le code suivant
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 procedure TForm1.FormCreate(Sender: TObject); var Row,Col: integer; Cells : array[1..3,1..5] of TWinControl; iLoc : integer; begin for iLoc := 1 to 5 do begin Cells[1, iLoc] :=TEdit.Create(ScrollBox2); with TEdit(Cells[1, iLoc]) do begin Parent := ScrollBox2; BorderStyle := bsSingle; Left := 18; Height := 24; Top := (iLoc-1)*Height; Text := 'Edit ' + IntToStr(iLoc); Visible := True; end; Cells[2, iLoc] :=TEdit.Create(ScrollBox2); with TEdit(Cells[2, iLoc]) do begin Parent := ScrollBox2; BorderStyle := bsSingle; Left := 18 + Cells[1,1].width; Height := 24; Top := (iLoc-1)*Height; Text := 'Edit ' + IntToStr(iLoc); Visible := True; end; Cells[3, iLoc] := TMemo.Create(ScrollBox2); with TMemo(Cells[3, iLoc]) do begin Parent := ScrollBox2; BorderStyle := bsSingle; Left := 18 + Cells[1,1].width + Cells[2,1].width; Height := 24; Top := (iLoc-1)*Height; Text := 'Memo ' + IntToStr(iLoc); Visible := True; end; end; Col := 1; Row := 1; { Cells[1, 1].SetFocus; OK mais pas dans Create} end;Je cherche une approche pour associer dynamiquement la méthode ci-dessus à l'événement OnKeyDown des TEdit(Cells[x]) créés dynamiquement. Encore faudrait-il créer l'événement correspondant et l'affecter aux "TEdits". Lazarus permet-il cela ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 procedure TForm1.EditxKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState ); // uses LCLType; begin case key of VK_UP: if Row > 0 then begin Dec(Row); Cells[Col, Row].SetFocus; end; end; end;
Merci. Gilles
Partager