|
|
|
Runtime event handler assignment
|
|
I suppose it's quite a dumb question, but I have never had to do such a thing in the past:
When creating a control (AButton:TSpeedButton to be precise) at runtime on SomeForm, how can I assign an event handler to AButton's OnClick event? The event hadler is already there, as it was created by Delphi for another button.
ANSWER
Just assign it as you would anything else...for example here's how I assign an OnClick event to a dynamically created set of TMenu Items derived from a TStringList:
Procedure TMainF.CreateMenu(Sender: TObject);
Var
NewMenuItem : TMenuItem;
Begin
For i := 0 To CategorySL.Count - 1 Do
Begin
NewMenuItem := TMenuItem.Create(Self);
NewMenuItem.AutoHotkeys := maManual;
NewMenuItem.Caption := CategorySL.Names[i];
NewMenuItem.OnClick := ChooseCat;
CategoryListPm.Add(NewMenuItem);
End;
End;
In this example, CategoryListPm is an empty TPopupMenu and "ChooseCat" is a procedure that runs the code for each it's OnClick event.
08.11.2004 [Število ogledov: 10] |
|
|
|
|
|
|
|
|
|
|
|
|
|
OBISKOV: 2358805 |
DATUM: 1.11.2024 |
URA: 0:59:23 |
IP: 3.145.167.176 |
|
|
|
|
|
|
|