Using IFunctionCallParameter
The Interface Consultingwerk.SmartFramework.IFunctionCallParameter is used to define the behavior of functions when for instance used to launch a form from the menu structure. There are a couple of different build in FunctionCallParameters coming with the SmartComponent Library.
The following standard FunctionCallParameters are available in the SmartComponent Library.
FunctionCallParameters | Purpose |
Consultingwerk.SmartFramework.InvokeServiceMethodCallParameter | Used to invoke a method from a service in the default service container. |
Consultingwerk.SmartFramework.InvokeStaticMethodCallParameter | Used to invoke a static method of a class. |
Used to launch a procedure. | |
Used to launch a GUI for .NET form | |
Used to launch a Web Site via URI. |
The following methods and properties must be implemented in the IFunctionCallParameter Interface:
Invokes/Starts the function associated with the IFunctionCallParameter object.
METHOD PUBLIC Progress.Lang.Object Invoke (plForceNewInstance AS LOGICAL, poContext AS Progress.Lang.Object)
Returns true when the function is currently active (running).
METHOD PUBLIC LOGICAL IsActive ()
Returns true when the function was successfully reactivated.
METHOD PUBLIC LOGICAL ReActivate ()
The following sections describe how you can define your own FunctionCallParameter and FunctionCallParamterControl. We will show you how to implement a class displaying a message when getting launched. The displayed message text will be configurable using the FunctionCallParameterControl.
The first step is to define the new FunctionCallParameter class. The name of this class will be ShowMessageCallParameter”.
The class and it’s properties must be serializeable so that they can be stored in the database.
CLASS Demo.FunctionCallParameterExample.ShowMessageCallParameter &IF NOT PROVERSION BEGINS "10.2":U &THEN INHERITS JsonSerializable &ENDIF IMPLEMENTS IFunctionCallParameter: {Consultingwerk/JsonSerializableProperty.i MessageText CHARACTER} .
The constructor of the class needs to add the serializable properties.
CONSTRUCTOR PUBLIC ShowMessageCallParameter (): SUPER (). &IF NOT PROVERSION BEGINS "10.2":U &THEN THIS-OBJECT:AddSerializableProperties ("{&SerializableProperties}":U) . &ENDIF END CONSTRUCTOR.
This message starts the function associated with the IFunctionCallParameter. Here the new message gets displayed to the user.
METHOD PUBLIC Progress.Lang.Object Invoke (plForceNewInstance AS LOGICAL, poContext AS Progress.Lang.Object): MESSAGE THIS-OBJECT:MessageText VIEW-AS ALERT-BOX. END METHOD.
The method returns true when the CallParameter type is loaded into the ServiceContainer.
METHOD PUBLIC LOGICAL IsActive (): RETURN VALID-OBJECT (FrameworkSettings:ServiceContainer:GetService (Progress.Lang.Class:GetClass ("Demo.FunctionCallParameterExample.ShowMessageCallParameter"))) . END METHOD.
The method returns true when the function is currently reactivated. You have to use the function when you reactivate the CallParamter type.
METHOD PUBLIC LOGICAL ReActivate (): THIS-OBJECT:Invoke (FALSE, ?) . RETURN TRUE . END METHOD.
In the next step we will build a control to customize our message text. This enables us to customize the message text within the Runtime-Environment without changing the code.
In this case we need to create a new UserControl inherited from Consultingwerk.Windows.Framework.Menu.CallParameterBaseControl and add a label and a multiline text editor (In this sample named: txtMessageText).
CLASS Demo.FunctionCallParameterExample.ShowMessageCallParameterControl
The InternalClearDataFields method is used to clear the UltraTextEditor text of the UserControl.
METHOD OVERRIDE PROTECTED VOID InternalClearDataFields (): ASSIGN txtMessageText:Text = "". END METHOD.
This method uses the current instance of the CallParameter class to display the current value. Thissample illustrates that the oCallParameter:MessageText gets assigned to the text property of the txtMessageText control.
METHOD OVERRIDE PROTECTED VOID UpdateUiData (): DEFINE VARIABLE oCallParameter AS Demo.FunctionCallParameterExample.ShowMessageCallParameter NO-UNDO. IF NOT TYPE-OF (CallParameterObject, Demo.FunctionCallParameterExample.ShowMessageCallParameter) THEN RETURN. oCallParameter = CAST (CallParameterObject, Demo.FunctionCallParameterExample.ShowMessageCallParameter). ASSIGN txtMessageText:TEXT = oCallParameter:MessageText. END METHOD.
This method updates the data of the FunctionCallParameter object after the user has entered data to the UI.
METHOD OVERRIDE PROTECTED VOID WritebackCallParameterToTextProperty (): DEFINE VARIABLE oCallParameter AS Demo.FunctionCallParameterExample.ShowMessageCallParameter NO-UNDO . oCallParameter = CAST (CallParameterObject, Demo.FunctionCallParameterExample.ShowMessageCallParameter). ASSIGN oCallParameter:MessageText = txtMessageText:Text. CATCH ple AS Progress.Lang.Error : Consultingwerk.Util.ErrorHelper:ShowErrorMessage (ple). END CATCH. END METHOD .
Aftercreating the ShowMessageCallParameter and the ShowMessageCallParameterControl classes we need to add them to the Consultingwerk.Windows.Framework.Menu.CallParameterControlFactory.This factory class is used to get the edit control type for a FunctionCallParameter class. The information is used in the Function Maintenance Form to display the needed control.
METHOD PUBLIC System.Windows.Forms.UserControl GetCallParameterControl (poCallParameterType AS Progress.Lang.Class):
The following ELS IF case needs to be added:
ELSE IF Progress.Lang.Class:GetClass ("Demo.FunctionCallParameterExample.ShowMessageCallParameter":U):IsA (poCallParameterType) THEN cUserControlClassName = "Demo.FunctionCallParameterExample.ShowMessageCallParameterControl":U.
Now, we can start the “Menu Function Maintenance”.
Press the Add button to create a new Maintenance Function.
You will see the newly created FunctionCallParameter in the drop down list.
Select the ShowMessageCallParameter, enter a new message text and save the new Function:
Now, we can set the text for our message box. I decide to type the text “My Message”.
Add the new Menu Function to the Menu Structure.
Here is the result of the Menu Demo Section.
you click on the menu you can see our MessageBox with the customized message text.