TFormAction (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example shows that OnClick is the default event of a form. When the form is created, the OnExecute event of its Action property is initialized to a user-defined procedure, which randomly changes the color of the form.

Code

void __fastcall TForm1::ChangeColor(TObject *Sender)
{
  // Randomly change the color of the form.
  Color = Random(0xFFFF);
}

__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
  // Allocate memory for the Action property.
  Action = new TBasicAction(this);

  // Set the OnExecute event handler.
  Action->OnExecute = ChangeColor;

  // Initialize the random number generator.
  Randomize();
}

Uses