[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
CppVclEvent

(C++ VCL) Event

'Something that can happen to a Control'.

Changing an Event at run-time

An OnClick Event is a pointer to a function (sometimes called a callback function), of type 'void __fastcall (TForm1::*)(TObject * Sender)'.

Like any pointer-to-function, you can change it at run-time, like the example code below:

__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
  Button1->OnClick = ClickOne;
  Button1->Click();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
  ++Timer1->Tag;
  if (Timer1->Tag % 2 ==0 )
  {
    Button1->OnClick = ClickOne;
  }
  else
  {
    Button1->OnClick = ClickTwo;
  }
  Button1->Click();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ClickOne(TObject *Sender)
{
  Button1->Caption = "One";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ClickTwo(TObject *Sender)
{
  Button1->Caption = "Two";
}
//---------------------------------------------------------------------------


'Event' links

Code links



last edited (April 5, 2007) by bilderbikkel, Number of views: 1047, Current Rev: 4 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.