KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Subform to Parent Form Communication with Recursive Objects
PRODUCT: 4D | VERSION: 20 | PLATFORM: Mac & Win
Published On: July 1, 2024

Sending data from parent form to child subform is relativiely straightforward. The "variable or expression" field can be set to be an object that the parent form can edit to send data to the child subform. However, when sending data in the other direction, from child subform to parent subform, it can be more complex. The following code uses recurisve objects to make this communication easier.

During the initialization of the child objects include the folllowing code:

Form.child:=New Object("parent"; Form)


This allows code in the child subform to read or write data in the parent subform by using:

Form.parent


Imagine that a user is choosing between options that are represented by subforms like so:



Sending the current selection data from the child to the parent is as easy as executing the following on click in the subform:

Form.parent.text:=Form.text
Form.parent.photo:=Form.photo

This technique helps modularize code by hiding complexity within subforms and restricts communication between components to the shared object.