Dynamic forms

KCML 5.02 introduced the Create() event which allowed a program to create a dynamic form by cloning controls already present on the template form. The .Create() event is a server side event that is notionally triggered before the form definition has been assembled to be sent to the client. If the form was designed with examples of the required controls already present then these controls can be cloned with one of a number of Duplicate() methods which allow the position, text etc. to be specified. There are special Duplicate() methods that apply to menus and tab controls allowing the menu to be constructed and pages to be added to tab controls.

A more powerful technique allowing users to edit forms directly was introduced in KCML 5.03. The basic form was provided by the programmer but the controls and their layout could be saved as a string and added to the form definition in the Create() event with an Import() method. See User Editable Forms for more details.

Sample program

00010 REM sample program showing Dynamic forms using EditForm()
    : REM example string defining static text
    : DIM z$="{.txtControl1,.static$,.Style=0x50000000,.Left=10,.Top=35,.Width=90,.Height=9,.Text$=""This is an on the fly control"",.Id=2000}"
    : DIM doedit=FALSE
    : - DEFFORM FORM1()=\
          {.form,.form$,.Style=0x50c000c4,.Width=261,.Height=118,.Text$="Dynamic form parent",.Id=1024},\
          {.ok,.button$,.Style=0x50010001,.Left=205,.Top=6,.Width=50,.Height=14,.Text$="Close",.__Anchor=5,.Id=1},\
          {.Play,.button$,.Style=0x50010000,.Left=205,.Top=28,.Width=50,.Height=14,.Text$="Display",.__Anchor=5,.Id=9},\
          {.Edit,.button$,.Style=0x50010000,.Left=205,.Top=50,.Width=50,.Height=14,.Text$="Edit",.__Anchor=5,.Id=1000}
    :     + DEFEVENT FORM1.Play.Click()
    :         REM display form2
    :         doedit = FALSE
    :         Form2.Open()
    :     END EVENT
    :     + DEFEVENT FORM1.Edit.Click()
    :         REM edit form2
    :         doedit = TRUE
    :         Form2.Open()
    :     END EVENT
    : FORM END
    : - DEFFORM Form2()=\
          {.form,.form$,.Style=0x50c000c4,.Width=216,.Height=94,.Text$="The dynamic form",.Id=1024},\
          {.ok,.button$,.Style=0x50010001,.Left=160,.Top=6,.Width=50,.Height=14,.Text$="Close",.__Anchor=5,.Id=1}
    :     + DEFEVENT Form2.Create()
    :         REM this is a dynamic form
    :         IF (doedit)
    :             Form2.form.EditForm(SYM(z$))
    :         ELSE
    :             Form2.form.Import(z$)
    :         END IF
    :     END EVENT
    : FORM END Form2
    : FORM1.Open()