RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TBitBtn.Action Property

Designates the action associated with the control.

Pascal
property Action: TBasicAction;
C++
__property TBasicAction Action;

Action is the action object that is associated with the control. Actions allow an application to centralize the response to user commands. When a control is associated with an action, the action determines the appropriate properties and events of the control (such as whether the control is enabled or how it responds to an OnClick event). 

To create actions at design time, place an action list component on a form or data module. Double click the action list to bring up the action list editor. Add actions in the editor using its context menu. Once the actions have been added using the action list editor, they appear in the drop-down list for the Action property in the Object Inspector.  

C++ Examples: 

 

/*
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 some user-defined procedure, which randomly changes
the color of the form.
*/
void __fastcall TForm1::ChangeColor(TObject *Sender)
{
  // randomly change the color of the form
  Color = Random(0xFFFF);
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  // allocate memory for the Action property
  Action = new TBasicAction(this);

  // set the OnExecute event handler
  Action->OnExecute = ChangeColor;

  // initialize the random number generator
  Randomize();
}

 

Delphi Examples: 

{
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 some user-defined procedure, which randomly changes
the color of the form.
}
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;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!