Super Control

Overview

A supercontrol is an advanced type of control. A supercontrol groups a set of controls for a specific purpose. These controls are independent from the processes of the window or page that hosts them. Benefits of supercontrols: the supercontrols are independent elements that can be easily reused regardless of the window or page where they are used. As they can be included in a dictionary, they can easily be transferred from a project to another one. Example: These three controls constitute a supercontrol. In this example, the button is used to automatically calculate the end date according to the period chosen in the popup menu of the button.


Two types of users are allowed to handle a supercontrol:
·       The creator of the supercontrol: person who designs the supercontrol as well as its features. For more details, see: Creating a supercontrol.
·       The user of the supercontrol: person who is including the supercontrol in his window (or page) and who will be using it by programming. For more details, see: Including a supercontrol in a window.
A supercontrol can include:
·       All types of controls, with all their characteristics (popup menu for example).
·       Specific procedures. These procedures are local to the supercontrol and they can be used by all the processes associated with the supercontrol or with one of its elements.
·       Some variables local to the supercontrol and that can be used by all the processes associated with the supercontrol or with one of its elements.
Note: A supercontrol can be created with a single control: this allows you to define procedures local to this control.

Creating a supercontrol in the editor
Two methods can be used to create a supercontrol:
·       Creating an empty supercontrol and creating the controls included in the supercontrol.
·       Creating a supercontrol from existing controls.
Note: No custom supercontrol can be added to the supercontrols proposed by WINDEV, WEBDEV and WINDEV Mobile.
Method 1
1.      In the window editor or in the page editor, on the "Creation" pane, in the "Containers" group, click "Supercontrol".
2.      Click the position where the control will be created in the window (or in the page). The outline of the supercontrol appears.
3.      Display the description of the control ("Description" from the popup menu).
4.      Add the different controls included in the supercontrol ([Add] button).
Caution: The controls associated with the supercontrol must belong to the supercontrol area defined in the editor. Otherwise, the control will be grayed in the editor and it will not be displayed at run time.
Method 2
1.      In the window editor or page editor, create the different controls that are included in the supercontrol.
2.      Select the controls ([Ctrl] key + mouse click or with the lasso).
3.      On the "Modification" pane, in the "Transformations" group, expand "Refactoring and swapping" and select "Create a supercontrol from the selection".
Note: The controls associated with the supercontrol are anchored in relation to the supercontrol (and not in relation to the window or to the page).
Supercontrols and scrollbars
A supercontrol contains a displayed area (black handles) and a displayable area (red handles).
To modify one of these two areas, move the handles while keeping the SHIFT key down.
If the displayed area is smaller than the displayable area, scrollbars are automatically displayed.
This is used to create supercontrols with scrollbars allowing you to scroll the supercontrol content.

Programming a supercontrol
Declaring the global variables of the supercontrol
The supercontrol includes a declaration code of global variables (see Processes associated with the supercontrol). This code is used to declare all the variables global to the supercontrol. All the types of variables are supported. They can be used in any process associated with the supercontrol or with one of the controls included in the supercontrol.
Declaring the functions and procedures linked to the supercontrol
To create a procedure local to the supercontrol:
1.      Display the supercontrol description.
2.      Click the "Add" button found below the "Local procedures" control. A new procedure is created.
3.      Click the "Code" button to edit the code of procedure.
Tip: To create local procedures linked to the supercontrol, you can perform the following operations:
1.      Select your window (or page) and the supercontrol in the "Project explorer" pane.
2.      Click the black arrow found beside the name of the supercontrol in the project explorer. The local procedures appear.
3.      Select "Local procedures". The local procedures displayed are the ones of the supercontrol. You have the ability to add, rename or delete local procedures in the supercontrol.
Accessing the supercontrol and the controls of supercontrol
When programming the supercontrol, you must access:
·       The supercontrol:
as the process must be independent of the supercontrol name, to find out the supercontrol name, we recommend that you use the MyParent keyword or functions such as ControlPopupOwnerControlCurrent, ...
·       The controls of supercontrol:
To do so, use the control variable in the code. From outside the supercontrol (code of popup menu of supercontrol control for example), you must use the following notation:
<Supercontrol Name>.<Control Name>
NoteEnumControl is used to list the controls belonging to a supercontrol.
Example
The following example corresponds to the code of an option in a popup menu. This menu is associated with a control of a supercontrol and it is used to modify the "StartDate" and "EndDate" controls of the supercontrol.
In this code, the name of the current supercontrol is returned by ControlPopupOwner. The controls found in the supercontrol are handled by the indirection operators.
// Retrieves the current supercontrol
sSuperControl is string
sSuperControl = ExtractString(PopupField(), 1".")
dDate is Date     // Today's date by default
// Goes to the previous day
dDate..Day--
// Displays the date of the previous day
{sSuperControl+".StartDate"}..Value = dDate
{sSuperControl+".EndDate"}..Value = dDate
Value of a supercontrol
A supercontrol includes several controls and it can return a value. This value can correspond to the value of a control found in the supercontrol or to any other information. This value is an empty string by default. It can be modified by ..Value or by direct assignment.
Example: A supercontrol is used to select a file. It contains an edit control and a button used to opens the file picker. The value of the supercontrol must correspond to the name of the selected file. To do so, the value of the supercontrol must be assigned:
·       in the modification code of the edit control,
·       in the click code of the selection button.
In this code, the MyParent keyword is used to designate the supercontrol in the code of one of its own controls.
// Modification code of the edit control
MyParent = MySelf
// Code of selection button
FileName = fSelect(fExtractPath(FileNamefDirectory), ...
fExtractPath(FileNamefFileName + fExtension), ...
"Select a file", ...
"All files (*.*)" + TAB + "*.*""")
MyParent = FileName
Functions and properties specific to the supercontrols
Functions specific to the supercontrols
The following functions are used to manage the characteristics of a supercontrol by programming.
Returns the name of the Nth control belonging to the supercontrol.
Specifies the useful size for the supercontrols with scrollbars.
 This function is not available.
Re-initializes the controls found in a supercontrol.

Properties specific to the supercontrols
The following properties are used to manage the characteristics of a supercontrol by programming.
Height
Used to find out and modify the height of the supercontrol.
Used to find out and modify the width of the supercontrol.
Used to find out the name of the supercontrol.
Used to find out and modify the value of the supercontrol.


Including a supercontrol in a window or in a page
Retrieving a supercontrol
In most cases, the supercontrol is available in a dictionary (.Dic file). To include the supercontrol in your window or page, you must:
1.      Display the "Dictionary" pane.
2.      Open the dictionary ("Open" from the popup menu).
3.    Drag and Drop the control found in the dictionary to your window or page. The supercontrol is automatically included in your window or page.


Note: Several copies of the same supercontrol can be found in the same window or page. Only the name of the supercontrol is modified. The names of the elements found in the supercontrol are not modified. The processes associated with the controls are independent.

Comments

Popular posts from this blog

Word Processing Control

Read XML String and load the data in Controls

Toast Display