CreateControl
CreateControl(iType, iStyle)
Create control in the Create event
iType | KCML_CONTROL_ENUM | Type of control to create |
---|---|---|
iStyle | KCML_STYLE_ENUM | Style bits |
Returns result of type OBJECT
Applies to: EditGroup , Form , GroupBox
Introduced in KCML version 7.09
CreateControl(iType, iStyle, objGroup)
Create control in the Create event
iType | KCML_CONTROL_ENUM | Type of control to create |
---|---|---|
iStyle | KCML_STYLE_ENUM | Style bits |
objGroup | Object | Optional group to which control should belong |
Returns result of type OBJECT
Applies to: EditGroup , Form , GroupBox
Introduced in KCML version 6.20
CreateControl(iType, iStyle, objGroup, objAfter)
Create control in the Create event, placing it after the specified control in the tab order
iType | KCML_CONTROL_ENUM | Type of control to create |
---|---|---|
iStyle | KCML_STYLE_ENUM | Style bits |
objGroup | Object | Optional group to which control should belong |
objAfter | Object | The new control will appear after this control in the tab order. If NULL then new control will appear at the end. To add to the front of the tab order pass the form object. |
Returns result of type OBJECT
Applies to: EditGroup , Form , GroupBox
Introduced in KCML version 6.20
The CreateControl() method allows controls to be created dynamically during the Create() event (except picture and color controls). The result is an object reference to the new control. This method can be called with two, three or four arguments, depending on requirements.
CreateControl is a method of the container class and is used to create controls on that container. Currently this includes forms, groupboxes and editgroups. Setting the position of a created control will place the control relative to its container, and it will remain in the same position on its container if the container is moved.
The style is dependent on the type of control. For most controls, either _STYLE_NORMAL or _STYLE_NOTABSTOP should be used, but see the comments below. For the style contants, refer to Constants.
The optional objGroup parameter is used to add the created control to a group. To allow events to be handled, all create controls must belong to a group defined in the DEF FORM itself. These groups can be created in the Forms Designer using the "Make Peristent Group ..." menu option. (The group must be persistent as the Forms Designer will remove redundant groups, and if all controls in the group are to be dynamic, then the group may appear to be redundant). The objGroup argument here should be an OBJECT representation of the control.
The optional objAfter parameter is used to specify the control on the form after which the new control will appear in the tab order. If NULL or omitted then the new control will appear at the end.
Create using _CREATE_DBEDIT
Use styles of _STYLE_DBEDIT, _STYLE_DBEDIT_DROPDOWN and _STYLE_DBEDIT_ELLIPSIS to create the three most common forms of dbedit.
Create using _CREATE_TABBED
The style of _STYLE_NORMAL should be used. Each page of the tab control is created using CreateTabPage(). Controls can be added to the created tab pages using the AddControl() method.
OBJECT TabControl = .form.CreateControl(_CONTROL_TABBED, _STYLE_NORMAL, OBJECT Group) OBJECT FrontPage = TabControl.CreateTabPage("&Main Details") OBJECT EditName = .form.CreateControl(_CONTROL_DBEDIT, _STYLE_DBEDIT, OBJECT EditGroup) REM Fill in EditName.Left, EditName.Top etc. FrontPage.AddControl(OBJECT EditName) OBJECT ContactPage = TabControl.CreateTabPage("&Contacts")
Create using _CREATE_MENU
To create a menu for the whole form, use _STYLE_MAIN_MENU, and set the Menu property of the form to the created menu. Add top-level menu items to the created menu using CreateMenuItem() and add sub menu items to these using CreateMenuItem().
OBJECT MainMenu = .form.CreateControl(_CONTROL_MENU, _STYLE_MAIN_MENU, OBJECT MenuGroup) OBJECT .form.Menu = MainMenu OBJECT FileMenu = MainMenu.CreateMenuItem("&File") OBJECT NewFile = FileMenu.CreateMenuItem("&New") OBJECT Exit = FileMenu.CreateMenuItem("E&xit", _MENUSTYLE_CLOSES) OBJECT EditMenu = MainMenu.CreateMenuItem("&Edit")
To create a popup menu use _STYLE_POPUP_MENU instead.
Create using _CREATE_RADIO and use style _STYLE_RADIO
To make several radio buttons belong to the same group they must set the object property ButtonGroup to the same object, typically the first control in the radio group
OBJECT Radio1 = .form.CreateControl(_CONTROL_RADIO, _STYLE_RADIO, OBJECT NULL) OBJECT Radio1.ButtonGroup = Radio1 OBJECT Radio2 = .form.CreateControl(_CONTROL_RADIO, _STYLE_RADIO, OBJECT NULL) REM Add this to the same group as Radio1 OBJECT Radio2.ButtonGroup = Radio1
Like other controls a color control can be created in the Create event, but also can be created later on, even after the form has been displayed
Like other controls a picture control can be created in the Create event, but also can be created later on, even after the form has been displayed