This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
While a code like this one can create the input fields and store the information you want in the "spare" property ComponentTag, so you can adjust things like maxlength, alignment accordingly, the #PRIM_MD.Edit does not really restricts the value to be numbers or characters or to handle the decimals on it properly......
Begin_Com Role(*EXTENDS #PRIM_WEB) Height(465) Width(881)
Define_Com Class(#STD_NUM.Visual) Name(#STD_NUM) Caption('Number of Fields') Displayposition(1) Height(19) Labeltype(Caption) Left(24) Parent(#COM_OWNER) Tabposition(1) Top(16) Width(193) Usepicklist(False)
Define_Com Class(#PRIM_PHBN) Name(#CREATE_FIELDS) Caption('Create Fields') Displayposition(2) Left(232) Parent(#COM_OWNER) Tabposition(2) Top(16) Width(113)
* Typical PRIM_MD.Edit definition... Componenttag is a "Generic space allowing a value to be stored for the instance" we can reuse it
Define_Com Class(#PRIM_MD.Edit) Name(#Edit1) Caption('Caption') Displayposition(3) Left(432) Parent(#COM_OWNER) Tabposition(3) Top(24) Componenttag('A(5)')
Define_Com Class(#STD_TEXT.EditField) Name(#STD_TEXT) Displayposition(4) Left(441) Parent(#COM_OWNER) Tabposition(4) Top(228)
Define_Com Class(#STD_AMNT.EditField) Name(#STD_AMNT) Displayposition(5) Left(446) Parent(#COM_OWNER) Tabposition(5) Top(129)
* Create one collection of PRIM_MD.Edit
Define_Com Class(#PRIM_KCOL<#PRIM_MD.Edit #STD_NUM>) Name(#EditFields) Reference(*DYNAMIC) Style(Collection)
Evtroutine Handling(#CREATE_FIELDS.Click)
If_Ref Com(#EditFields) Is_Not(*null)
Set_Ref Com(#EditFields) To(*null)
Endif
* Create the collection
Set_Ref Com(#EditFields) To(*Create_as #PRIM_KCOL<#PRIM_MD.Edit #STD_NUM>)
#std_int := 0
Begin_Loop To(#STD_NUM)
* Set the attributes for each one, lets say, alternate between A(20) and S(9)
#std_int += 1
Set_Ref Com(#EditFields<#std_int>) To(*CREATE_AS #PRIM_MD.Edit)
If (#STD_int.mod( 2 ) = 0)
Set Com(#EditFields<#std_int>) Width(200) Displayposition(#std_int) Tabposition(#std_int) Parent(#COM_OWNER) Caption('Field A(20)') Height(55) Top((60 * #std_int)) Componenttag('A(20)') Maxlength(20)
Else
Set Com(#EditFields<#std_int>) Width(200) Displayposition(#std_int) Tabposition(#std_int) Parent(#COM_OWNER) Caption('Field S(9,4)') Height(55) Top((60 * #std_int)) Componenttag('S(9,4)') Maxlength(9) Displayalignment(Right) Editalignment(Right)
Endif
End_Loop
Endroutine
End_Com
.... So, I would be more inclined to use fields like STD_ or my own set of standard fields (kind like Data Types in the Data Modeller) and create collections using those fields. That way, you can have not just control of the content of the field, but even field visualizations of all kind at your disposition, even dates, dropdowns, etc: