How Action Links are Used
Go Up to FireMonkey Actions
Programs use action links to connect actions to clients. In this topic we discuss how such links are implemented.
Types of Action classes
Appmethod's implementation of actions uses the following three most important types of action classes:
- TAction classes. TAction and descendant classes define FireMonkey action objects. TAction and descendant classes implement actions to be used with controls, menu items, and tool buttons. The published properties and events of actions can be managed in the Object Inspector at design time.
- TActionList class. The TActionList class maintains a list of actions that can be used by client components such as controls, menu items, and tool buttons. TActionList lets you set up actions using the Action List editor.
- TActionLink classes. TActionLink and descendant classes define action links. An action link connects an action to a client (objects, components, and controls). The client is the parameter to the TActionLink constructor, and the assigned action object is indicated by the TBasicActionLink.Action property. An action link object also sets up links between an action and client's properties, execution and updating events.
- Actions allow an application to centralize the response to user commands. When an action link associates a client with an action, the action determines the appropriate properties and events of the client (such as whether the client is enabled or how it responds to an OnClick event).
When designing Appmethod applications, the programmer typically assigns actions to a client (control, menu item, tool button, or any other TFmxObject type component that supports the Action property).
How to assign an Action to a Client
At design time, you can make this assignment using the following algorithm:
- In the Form Designer, select your client component (an object that can be cast to the TFmxObject type). If the selected component has the published visibility of the Action property, then this property appears in the in the Object Inspector.
- In the Object Inspector, select the Action item and click the down arrow on the right. Choose the action you want to assign to the client.
At run time, you can simply assign the desired action to the Action (TFmxObject.Action) property of a client object.
How to access an Action property
Assigning or getting an action to or from the Action property is not a direct operation. The Action property has the following declaration:
property Action: TBasicAction read GetAction write SetAction;
Notice that the TFmxObject class does not have an FAction field. The private setter SetAction and getter GetAction sets and retrieves, respectively, action values from the Action property of the proper TActionLink kind object. The setter and getter retrieve a TActionLink kind of object by calling GetActionLinkClass.
The core of the SetAction setter looks like this:
procedure TFmxObject.SetAction(const Value: TBasicAction); var lClass: TActionLinkClass; begin lClass := GetActionLinkClass; FActionLink := lClass.Create(Self); ActionLink.Action := Value; end;
declares the lClass variable, whose value is the class reference for the TActionLink class or for one of its descendants. To understand this code, notice that the TFmxObject class declares the read-only ActionLink property, which is stored in the FActionLink field:
property ActionLink: TActionLink read FActionLink;
The SetAction setter sets the
ActionLink.Action property in the action link object associated with the client. This action link object is created and assigned to FActionLink by:
FActionLink := lClass.Create(Self);
The following code retrieves the lClass class reference value:
lClass := GetActionLinkClass;
GetActionLinkClass returns the associated action link class. To retrieve an Action, the client object calls GetAction:
function TFmxObject.GetAction: TBasicAction; begin if Assigned(FActionLink) then Result := FActionLink.Action end;
This example again uses the action link object stored in the FActionLink property.
That is, client objects do not keep an associated action explicitly. The action is stored in the associated action link object. The getter GetAction and setter SetAction retrieve and set, respectively, an action from or to the Action property of this action link object.
If GetActionLinkClass returns a non-
nil value, then the action object is assigned to Action. If the control object does not support actions, then GetActionLinkClass should return
nil. In this case, attempting to set a value to the Action property raises the following exception:
StrEActionNoSuported = 'Class %s does not support the action'
Notice the ActionClient property:
property ActionClient: boolean read FActionClient;
The ActionClient property depends on the value of Action:
Action = nilthen
ActionClient = False. This means that this component object is not a client of any action.
Action <> nilthen
ActionClient = True. This means that this component object is a client of some associated action. After changing of the ActionClient property, the virtual DoActionClientChanged method is called.
- Note: Action link classes are an internal feature of Appmethod. You do not need to use action link classes explicitly in an application, unless you create your own type of client components. If, for example, your client component has some new properties, then it needs that the proper action link object controls the states of these properties. Therefore, you may need to extend some action link class to handle these properties.
- Using Action Lists
- Predefined Action Classes
- Registering Actions