Board index » delphi » OnClick Event with a run-time create button
Balet Charles-Henri
![]() Delphi Developer |
Tue, 09 Jan 2001 03:00:00 GMT
|
Balet Charles-Henri
![]() Delphi Developer |
Tue, 09 Jan 2001 03:00:00 GMT
OnClick Event with a run-time create button
Hello,
who can help me to assign an procedure to an Button create in Run Time with btn := TButton.Create(Self); the compiler return an error with incompatibility on TNotify Event and can you help me ? thanks |
GWhit419
![]() Delphi Developer |
Tue, 09 Jan 2001 03:00:00 GMT
Re:OnClick Event with a run-time create buttonHi, I've found that the easiest way to attach events to components created at ie {$R *.DFM} procedure TForm1.FormCreate(Sender: TObject); end. Gordon |
CEHJohns
![]() Delphi Developer |
Tue, 09 Jan 2001 03:00:00 GMT
Re:OnClick Event with a run-time create button"Balet Charles-Henri" <char...@prolec.ch> writes: Quote>who can help me to assign an procedure to an Button create in Run Time with type TMyType=procedure(var1:type1;var2:type2[;var3:type3...]) of object; I know what type TMyType=procedure(var1:type1;var2:type2[;var3:type3...]) means, but "of object" makes no sense to me. These things can be confusing, as there are several layers of abstraction type TNotifyEvent = procedure (Sender: TObject) of object; This is used for On*** event properties which are essentially method pointers. When the user clicks the left mouse button on the control, TControl traps this if PtInRect(...) then Click Now, Click is another method of TControl. What do we see in Click?.... if Assigned(FOnClick) then FOnClick(Self); FOnClick is the private field of TControl's OnClick event property. property OnClick: TNotifyEvent read FOnClick write FOnClick; This is what we see and use as component consumers! In practice what that procedure TSomeClass.ProcedureName(Sender: TObject); I hope that answers both your questions Charles Johnson |
AlanGLLo
![]() Delphi Developer |
Wed, 10 Jan 2001 03:00:00 GMT
Re:OnClick Event with a run-time create buttonIn article <6pa4k9$dn...@bw107zhb.bluewin.ch>, "Balet Charles-Henri" Quote<char...@prolec.ch> writes: 2 It must be a method - ie defined as TSomeObjectType.OnSomeEvent(Sender : TObject); If you look up TNotifyEvent (which is the type of the event handling method ) . . . which is a succint way of saying what is in 1 and 2 above. So write a method :- procedure TForm.WhatIDoWhenAButtonIsClicked(Sender : TObject); put . . . procedure WhatIDoWhenAButtonIsClicked(Sender : TObject); . . . immediately before the private clause in the interface section of your then code . . . Btn.OnClick := WhatIDoWhenAButtonIsClicked; . . . that's it You can call the procedure what you like but it's best to call it Alan Lloyd |
Meepmill
![]() Delphi Developer |
Thu, 11 Jan 2001 03:00:00 GMT
Re:OnClick Event with a run-time create buttonthe "Of Object" part just lets the compiler know that the procedure/function will/can be called as part of a classes event handler ie and OnClick event. -apm Quote>WGabor writes: |
1. "Runtime created button"onclick event linking
2. "Runtime created button"onclick event linking(2)
3. Onclick event in dynamically created button
4. How do I create a Button1.OnCLick event at RunTime
5. Creating buttons at run-time
6. Creating a Button at run time on a panel
7. Creating a Button at run time on a panel