Creating ATEasy Controls Dynamically

Knowledge Base Article # Q200169

Read Prior Article Read Next Article
Summary This article discusses how to create controls dynamically and access them from control arrays.
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:

Module Variables:
objGB:  AGroupBox
objLBL:  ALabel
aobjGroup:  ASwitch[8]

lWidth:  Long
lHeight:  Long
lPosX:  Long
lPosY:  Long
i:  Long


!  Add new GroupBox control to form "MyForm" and set the Caption property
objGB.Caption="Run-Time Controls"

! Add new Label control to form "MyForm" and set properties
objLBL.Font.Name="MS Sans Serif"
objLBL.Caption="Byte Value"

! 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

OnSwitchChange Procedure(objCtrl):
objCtrl:  VAL AControl
lByteValue:  Long
i:  Long

For i=0 to 8

Creating ATEasy Controls Dynamically
Figure 1 - Design Time and Run Time generated controls

Refer to the Forms.PRG example in the ATEasy Examples.

Article Date 6/16/2009 3:29:18 PM
Keywords ATEasy, array, control, InsertControl, AddHandler, dynamic controls

1 ratings | 5 out of 5
Read Prior Article Read Next Article