TFormAction (Delphi)

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

procedure TForm1.ChangeColor(Sender: TObject);
begin
  { Randomly change the color of the form. }
  Color := Random($FFFF);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  { Allocate memory for the Action property. }
  Action := TBasicAction.Create(Self);

  { Set the OnExecute event handler. }
  Action.OnExecute := ChangeColor;

  { Initialize the random number generator. }
  Randomize;
end;

Uses