KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Replace Process Variables Bound to Input Boxes With Dynamic Variables
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac & Win
Published On: November 29, 2022

In general, it is a good rule of thumb to minimize the use of process variables in your 4D applications. There are many reasons why, such as having to declare each and every variable for compilation and preventing memory overload as new processes are booted up, and more.

One way to replace process variables is by using dynamic variables; these variables are internally created by 4D when a form object is not connected to a variable or expression. This is especially useful when a form initially contains input boxes bound to process variables (see below).



To replace these process variables, you can use the following steps:


  1. In the form editor, create or select the input box that you would like to apply a dynamic variable to.

  2. Assign this object a unique name; this is important as the object name will act as the unique identifier for the pointer. In the property list window, ensure that the “Variable or Expression” property is set to blank.



  3. Depending on how your application is designed, you can use the command, OBJECT Get pointer, to assign a value to the dynamic variable (in this case, the code is inserted into a button’s object method that will execute when the button is clicked):

  4. // local variable
    $userInput:=OBJECT Get pointer(Object named; "Input")->

    // form data
    Form.userInput:=OBJECT Get pointer(Object named; "Input")->

    // current or entity selection
    Form.currentSelection.userInput:=OBJECT Get pointer(Object named; "Input")->


  5. In a similar fashion, you can give the input box a value from the dynamic variable before the user edits his or her input.


  6. // form data
    OBJECT Get pointer(Object named; "Input")->:=Form.userInput

    // current or entity selection
    OBJECT Get pointer(Object named; "Input")->:=Form.currentSelection.userInput


  7. Run your application with the debugger to ensure the user’s input was successfully assigned.



You have now successfully replaced the process variable with a dynamic variable.