Every application action must have a trigger so that users are able to perform it.
There are 6 ways to create a trigger for an action:
From the point of visual representation and user interaction, all triggers are the same – regardless of the way they were created by.
What is different is how they are processed and their data is stored by Lycia.
This means that even though end users of your application will see no difference, you will use different methods to manipulate different triggers.
We do not recommend mixing different ways of creating triggers for one application.
You work on the application will be quicker and easier if you choose one way and use it to create all triggers.
If an action is not associated with any trigger, Lycia will create it automatically in the form of a toolbar button:
...
ON ACTION act1
DISPLAY "one"
...
At runtime,
4gl developers can manipulate automatically created triggers by these functions:
For example,
CALL fgl_setactionlabel("act1", "one", "qx://application/filter_1.svg", 1, FALSE, "This is a toolbar button #1", "top")
...
ON ACTION act1
DISPLAY "one"
...
The usual way to create a trigger for an action is to add a corresponding widget to an .fm2 form.
Most often, actions are triggered by these widgets:
You can also use these widgets to trigger an action:
To use a widget as a trigger for the action, you must follow these steps:
...
ON ACTION act1
DISPLAY "one"
...
You can read about adding widgets to the form on every widget's page, e.g., ToolbarButton or MenuCommand.
Usually, these events are available – onInvoke, onTouched, onKey, and onMouse:
To associate the trigger with a definite property, you must use the same name as in the 4gl code:
Now the trigger is added to the form and action can be performed at runtime:
4gl developers can manipulate these widget triggers by their properties (as shown above) or via the corresponding ui methods.
This way is close to the previous one but requires a certain level of 4gl expertise.
To be able to create triggers in this way, you must know how to create and manipulate the elements of the ui.<Widget> data type and how to use different ui methods.
You can read about ui methods and elements in the page of the corresponding widget. For example, ui.Button or ui.MenuCommand.
To create a trigger for the action by ui methods, you must follow these steps:
...
ON ACTION act1
DISPLAY "one"
...
DEFINE tb_button ui.ToolbarButton
DEFINE buttonEvent ui.BackgroundServerEventHandler
Please remember that some widgets – like Button, MenuBar, or ToolbarButton – can be created by ui methods at runtime and other widgets – like Toolbar – cannot be created by ui emthods at runtime and must be added to the form in Lycia Form Designer.
Here is an example of creating a toolbar button by ui methods at runtime:
DEFINE tb_group ui.ToolbarGroup
DEFINE tb_button ui.ToolbarButton
...
LET tb_group = ui.ToolbarGroup.Create("tbg","toolbar")
LET tb_button = ui.ToolbarButton.Create("bt1","tbg")
CALL tb_button.SetText("form button")
LET buttonEvent = ui.BackgroundServerEventHandler.Create()
CALL buttonEvent.SetCallBackAction("display")
CALL tb_button.SetOnInvoke(buttonEvent)
Do not forget to use the correct names of the actions.
4gl developers can manipulate these triggers by the corresponding ui methods (e.g., setText(), setImage(), setTooltip(), etc).
Every form element of a .fm2 form file has a property, actions, that allows creating triggers for application actions:
This property has all the attributes of the trigger:
To create a trigger for the action in a .fm2 form directly, you must follow these steps:
...
ON ACTION act1
DISPLAY "one"
...
Specify its identifier – to associate the trigger with a definite property, you must use the same name as in the 4gl code.
More details about the property, actions, is here.
SystemActionDefaults.fm2 is a global configuration file containing the predefined application actions, i.e. the application actions applied to all Lycia-based 4gl applications. However, if you need to customize action defaults, configure the Master action defaults file or User action defaults file: they override the System action defaults file. The System action defaults file can be overwritten at Lycia updates, so please refrain from editing it.
Master action defaults file is an action defaults file that contains default attributes for actions that can be performed in the 4gl application. Master action defaults files have the name of the program, are stored together with it, and are loaded automatically when the application is run.
User action defaults file is a user-defined configuration file with extension .ad2 or .fm2 that contains default attributes for actions that can be performed in several different 4gl applications in order to secure their common runtime behavior or change it according to current tasks and purposes. It has a higher priority than the Master action defaults file.
All these files have the same basic structure as any .fm2 form including the property, actions, that is used to create triggers for the application actions.
The algorithm of creating a trigger for an application action in an action defaults file is almost the same as in the .fm2 form directly. The difference is in the scope to which this action will be applied:
To create a trigger for the action in an action defaults file, you must follow these steps:
...
ON ACTION act1
DISPLAY "one"
...
Specify its identifier – to associate the trigger with a definite property, you must use the same name as in the 4gl code.