Tech Tip: Passing an entity into form data attribute instead of direct form data
PRODUCT: 4D | VERSION: 17 | PLATFORM: Mac & Win
Published On: June 21, 2019
It is recommended to pass an entity into a form data attribute instead of directly as form data in order to successfully use the entity's member functions. Let's take for example a listbox row is double clicked to show an input form containing entity data where the previous and next buttons need to be programmed to show the following entity.
Case of : (Form event=On Double Clicked) C_OBJECT($form_o) $form_o:=Form.currItem // entity passed directly into object "Form" C_LONGINT($win_l) $win_l:=Open form window("Form1") DIALOG([Contact];"Input2";$form_o) CLOSE WINDOW($win_l) End case |

Within the next button, the code is as follows:
C_OBJECT($ent_e) $ent_e:=Form.next() If ($ent_e#Null) Form:=$ent_e // Syntax error: special object "Form" is not assignable End if |
However, the special object Form is not directly assignable which shows the limitation of passing an entity directly as form object.

Instead, simply pass the entity as an attribute of the form object and update the input form's objects as shown below.
Case of : (Form event=On Double Clicked) C_OBJECT($form_o) $form_o:=New object $form_o.ent:=Form.currItem // entity passed as an attribute of form data C_LONGINT($win_l) $win_l:=Open form window("Form1") DIALOG([Contact];"Input2";$form_o) CLOSE WINDOW($win_l) End case |

Now in the next button code, there is no situation where Form needs to be directly assigned and Form.ent can be used instead.
C_OBJECT($ent_e) $ent_e:=Form.ent.next() If ($ent_e#Null) Form.ent:=$ent_e End if |
Finally, when the next button is clicked, the form data will successfully move to the next entity.
