KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: View a form via subform with a dynamic form
PRODUCT: 4D | VERSION: 17 | PLATFORM: Mac & Win
Published On: August 16, 2018

Here is a utility method to view a project form that is viewed as a subform of a dynamically generated form:

// -----------------------------------------------------------------
// Name: DISPLAY_SUBFORM_DYNAMICALLY
// Description: Method will create a form with a Subform object
// specified.
//
// Input Parameters:
// $1 (TEXT) - Name of the Project Form or JSON definition
// $2 (LONGINT) - Left coord in the form for Subform object
// $3 (LONGINT) - Top coord in the form for Subform object
// $4 (LONGINT) - Width size in pixels for Subform object.
// $5 (LONGINT) - Height size in pixels for Subform object.
// ------------------------------------------------------------------
C_TEXT($1;$formNameorLoc;$tableName)
C_LONGINT($2;$left)
C_LONGINT($3;$top)
C_LONGINT($4;$width)
C_LONGINT($5;$height;$pos;$pos2)
C_OBJECT($subF;$form;$pageM)

If (Count parameters=5)
  $formNameorLoc:=$1
  $left:=$2
  $top:=$3
  $width:=$4
  $height:=$5
  
  $formNameorLoc:=Lowercase($formNameorLoc)
  $pos:=Position(".json";$formNameorLoc)
  
  If ($pos>0)
    $pos:=Position("resources";$formNameorLoc)
  
    If ($pos>0) // Is in the Resources folder
      $formNameorLoc:=Substring($formNameorLoc;$pos;Length($formNameorLoc)-$pos+1)
      $formNameorLoc:=Replace string($formNameorLoc;Folder Separator;"/")
    End if
  Else
   //Determine if it is Table form or Project Form
  $pos:=Position("[";$formNameorLoc)

   $tableName:=""
   If ($pos>0)
    $pos2:=Position("]";$formNameorLoc;$pos+1)
    $tableName:=Substring($formNameorLoc;$pos+1;$pos2-$pos-1)
    $formNameorLoc:=Substring($formNameorLoc;$pos2+1;Length($formNameorLoc)\
    -$pos2+1)
   End if
  End if
  
  $subF:=New object("type";"subform";"left";$left;"top";$top;"width";$width;\
  "height";$height;"table";$tableName;"detailForm";$formNameorLoc)
  $pageM:=New object("objects";New object("subF";$subF))
  $form:=New object("pages";New collection(Null;$pageM))
  
  $window:=Open form window($form)
  DIALOG($form)
  CLOSE WINDOW($window)
End if


Here is an example of a project form "FormSample" that was created by the form editor:




Example #1: Calling the project form

C_TEXT($loc)
C_LONGINT($left;$top;$width;$height)

$left:=0
$top:=0
$width:=250
$height:=335
$loc:="FormSample"

DISPLAY_SUBFORM_DYNAMICALLY ($loc;$left;$top;$width;$height)


Example #2: Calling the table form

$loc:="[Table_1]Input"

DISPLAY_SUBFORM_DYNAMICALLY ($loc;$left;$top;$width;$height)


Here is the same form as a JSON defninition:

{
  "left": 0,
  "top": 0,
  "width": 252,
  "height": 340,
  "pages": [
      null,
      {
       "objects": {
       "text": {
        "type": "input",
        "text": "",
        "top": 20,
        "left": 20,
        "width": 214,
        "height": 16
       },
       "myListBox": {
        "type": "listbox",
        "listboxType": "array",
        "top": 54,
        "left": 20,
        "width": 214,
        "height": 220,
        "scrollbarHorizontal": "hidden",
        "columns": [
           {
             "objectName": "Header1",
             "dataSource": "",
             "width": 212,
             "header": {
               "text": "Header1"
               }
           }
         ]
        },
        "button": {
         "type": "button",
         "text": "Button",
         "top": 292,
         "left": 17,
         "width": 214,
         "height": 26
         }
        }
       }
      ]
}


Example #3: Calling a JSON file definition from "Resources" folder:

$loc:=Get 4D folder(Current resources folder)+"formSample.json"
DISPLAY_SUBFORM_DYNAMICALLY ($loc;$left;$top;$width;$height)


Example #4: Calling a JSON file definition next to structure files:

$loc:="formSample.json"
DISPLAY_SUBFORM_DYNAMICALLY ($loc;$left;$top;$width;$height)


See Also: