There are two processes for adding controls to a form in ATEasy, at design time, and dynamically at run time. The topic of adding controls at design time and referrencing the control objects from an array are discussed in Knowledgebase article Q200161. This article is an extension of Q200161 and will focus on using arrays to access controls that were placed on the form dynamically at run time.
The InsertControl() method allows you to create a control during run-time. The syntax is:
[ ctrl = ] Object.InsertControl ( sControlName, sControlClassType, [fLeft], [fTop], [fWidth], [fHeight], [sContainer], [bVisible], [vNameOrIndex] )
A full description of this method, and the associated AddHandler statement can be found in the ATEasy help document. An example of inserting a new GroupBox with eight Switches and a Label onto an existing ATEasy form is shown below. This code duplicates controls that were placed on the form at design time. Note: Code for setting the dynamically created controls properties and creating an event handlers, while not discussed, were included for completeness. The resulting form and controls are shown in figure 1:
! Add new GroupBox control to form "MyForm" and set the Caption property
! Add new Label control to form "MyForm" and set properties
objLBL.Font.Name="MS Sans Serif"
! Add eight Switch control to the new GroupBox control and set properties
For i=0 to 7
! Add an OnSwitchChange event handler for each new switch created
AddHandler aobjGroup[i], "OnChange", OnSwitchChange
objCtrl: VAL AControl
For i=0 to 8
Figure 1 - Design Time and Run Time generated controls
Refer to the Forms.PRG example in the ATEasy Examples.