CPB Mailing List
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Assigning an event handler at runtime?
On Tue, 26 Aug 1997, Lee Morrison wrote:
> Does anyone know how to set the value of an event (OnClick) belonging to a
> control (TSpeedButton) at runtime? Since I'am working with a component I
> can't assign it through the Events tab of the Object Inspector.
>
First you must define a TNotifyEvent function in your MainForm's class
as follows.
in .h file:
<html>
<pre>
class TMainForm : public TForm
{
__published: // IDE-managed Components
TSpeedButton* SpeedButton1;
void __fastcall FormCreate(TObject *Sender);
private: // User declarations
public: // User declarations
void __fastcall MyOnClick(TObject *Sender); // The TNotifyEvent
__fastcall TMainForm(TComponent* Owner);
};
</pre>
</html>
In .cpp
<html>
<pre>
...
void __fastcall TMainForm::FormCreate(TObject *Sender)
{
...
SpeedButton1->OnClick = MyOnClick;
...
}
...
void __fastcall TMainForm::MyOnClick( TObject *Sender)
{
// Place your event Handler code here
}
\|/ Robert E. Twitty, rtwitty@ushmm.org
--*-- Computer Systems Developer
/|\ US Holocaust Memorial Museum, (202) 488-6598
</pre>
</html>
W Komornicki's Home Page |
Main Index |
Thread Index