KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Method to retrieve all forms in an object array
PRODUCT: 4D | VERSION: 15 | PLATFORM: Mac & Win
Published On: October 27, 2015

Below is a method to return all form names (project and table forms) in an object array. The objects in the array will contain several properties. The first is "Form Type" to determine if the form is either a project form, or a table form. If the form type is a table form, both the table name, and the table number are included as properties in the object. The last property is the actual name of the form.

ARRAY TEXT($arrnames;0)
ARRAY TEXT($arrTableTitles;0)
ARRAY LONGINT($arrTableNums;0)
C_OBJECT($ob)
ARRAY OBJECT($arrObjForms;0)
C_POINTER($arrObjPointer;$1)
$arrObjPointer:=$1

//Append project forms
FORM GET NAMES($arrnames;*)
For ($i;1;Size of array($arrnames))
   OB SET($ob;"Form Type";"Project Form";"Form Name";$arrnames{$i})
   APPEND TO ARRAY($arrObjPointer->;$ob)
   CLEAR VARIABLE($ob)
End for

//Append table forms
GET TABLE TITLES($arrTableTitles;$arrTableNums)
For ($i;1;Size of array($arrTableNums))
   $tablePtr:=Table($arrTableNums{$i})
   FORM GET NAMES($tablePtr->;$arrnames;*)
   For ($j;1;Size of array($arrnames))
      OB SET($ob;"Form Type";"Table Form";"Table Name";$arrTableTitles{$i};"Table Num";$arrTableNums{$i};"Form Name";$arrnames{$j})
      APPEND TO ARRAY($arrObjPointer->;$ob)
      CLEAR VARIABLE($ob)
   End for
End for


Example:

A database contains the following forms:


To obtain a list of forms programatically, run the following code using the method above:
ARRAY OBJECT($arrForms;0)
UTIL_GET_FORMS (->$arrForms)


The code yields the following results: