Tech Tip: Output Subforms and Object Get Subform
PRODUCT: 4D | VERSION: 16 | PLATFORM: Mac & Win
Published On: January 11, 2018
When in design mode, an output subform cannot be properly tested by simply pressing the green button to run a form method if assigning the subform programatically is desired. The reason for this is that the subform does not load until the method creating it completes.
In the below screenshot a subform object is placed inside a form and set simply as an output subform with no source, and the form run using the green arrow. The button on the form should be programmatically setting the subform but it does not seem to work!
In order to test this, the form with the output subform needs to be opened as a process. To open the form in a process, use a simple method to launch the form like this:
$win:=Open form window("Form1") DIALOG("Form1") CLOSE WINDOW($win) |
Now the output subform can be created and tested as desired:
To programmatically set a subform the command OBJECT SET SUBFORM can be used:
OBJECT SET SUBFORM(*;"Subform_1";[Documents];"Documents_Output") |
To get information about a subform, the command OBJECT GET SUBFORM can be used, the timing is important here. Since the subform is not loaded until the method is complete, if OBJECT GET SUBFORM is used just after OBJECT SET SUBFORM in the same method, the get will not work since the subform is not loaded until the method is complete.
This method below will set the form, but the OBJECT GET SUBFORM will not return any information since the method needs to complete before the form is set:
OBJECT SET SUBFORM(*;"Subform_1";[Documents];"Documents_Output") // this GET will not return info since it is in the same method as the SET! OBJECT GET SUBFORM(*;"Subform_1";$subForm_p;$subFormName_t) |
To use the OBJECT GET SUBFORM command make sure the method containing the OBJECT SET SUBFORM has completed and then make the call for the get to pull the info about the form. As a note, if the above method with the setting and getting of the subform were to be called twice, the second time the get would return information but this is from the first call!
As a note, the LISTBOX SET TABLE SOURCE and LISTBOX GET TABLE SOURCE commands operate in the same manner and should not be called in the same method.