V14: pass the subform object-data


In Ergänzung zu On Bound Variable Change.

Ändert sich der Wert der einer Subform zugewiesenen Variablen, reagiert die Subform, wenn ich das so will. Ändert sich was in der Subform kann sie über CALL SUBFORM CONTAINER im Master-Formular eine Reaktion anstoßen. Das ist kompliziert und es kann dauern, bis der Groschen fällt.

Die einer Subform zugewiesene Variable kann verschiedene Datentypen haben. Ich nehme meist Text oder Longint als Datentyp der Subform. Das reicht, um eine Datensatznummer oder ein Stück Text als Kommunikation auszutauschen. Doch manchmal reicht es nicht hin, nur einen Wert zu übergeben. Ab V15 steht das Object als Datentyp für die Subform-Variable zur Verfügung. In V14 können wir den fehlenden Datentyp Object über Konvertierung in den Datentyp Text kompensieren.

Ich habe es ausprobiert und diese hübsche Anwendung in V14 entworfen. Das Masterformular ist rot/grau und die eingebettete Subform grün/gelb abgesetzt.

subformObjVar

Eine Änderung der Listboxdaten im roten Master-Formular führt zu einer Änderung der Listbox in der grünen Subform. In umgekehrter Richtung funktioniert der Datenabgleich auch. Das sieht nach Arbeit aus. Wie verpacken und wissen welcher Wert geändert wurde und den Wert selber. Alles in Text packen? Ja, so was in der Art.

In diesem Beispiel werden die beiden Arrays der Listbox zeilenweise in Objekte verpackt und die Objekte in ein Objektarray. Das Objektarray dann der Subform-Variablen zugewiesen.

In V14 braucht es einen Zwischenschritt. Im Master-Formular wird das Objektarray in Text gewandelt (JSON Stringify array) und dieser Text der Subform-Variablen zugewiesen. Ruft die Subform das Masterfomular, hat diese die Konvertierung in Text bereits ausgeführt. Das Masterfomular parsed diesen Text der Subform-Variablen (JSON PARSE ARRAY), packt die Objekte aus und weist die Werte den Array-Zeilen zu. Die Datentyp-Konvertierung an beiden Orten – Object → Text → Object – können Sie sich in V15 sparen und direkt mit einer Subform-Variablen vom Datentyp Object arbeiten. Entwicklen Sie diese Kommunikation in V14, schieben Sie notwendige Anpassungsarbeit nicht bis zur die V15 vor sich her. 4D ist mehr als schnell genug, um einige zig Hundert Datentyp-Konvertierungen auszuführen.

Verwirrt? Schauen sich die Vorgehensweise im Beispiel an, laden Sie die V14-Datenbank.

Rückmeldungen bitte per Mail. Wordpress läßt zu viele Spam-Kommentare durch und das macht Arbeit. Wollen Sie einen Kommentar hinzufügen, mache ich das gerne für Sie.



Follow-up on On Bound Variable Change.

As soon as the variable-content changes, the subform reacts as defined by code. If some value inside the subform changes, the subform triggers  CALL SUBFORM CONTAINER and starts a reaction inside the master-form. This reads complicated and it is until you get the point.

The subform-variable can be defined with different datatypes. I prefer text or longint as datatype for the subform-variable. This is sufficient to exchange a record-ID or some meaningful string. Sometimes sending just one value is not enough. Starting V15 the subform-variable might be of datatype object. Using V14 you might compensate for the missing datatype and send the object as a text.

I tried it and created this nicely coloured V14-application. The master form is red/grey and the subform green/yellow.

subformObjVar

Changing listbox-content on the red master-form changes the contents of the listbox on the green subform and vice versa. How to know which value to change and the value itself? Looks like work to be done, easily getting into something bloated.

Can be simplified. Every single listbox-row is put into an object and the objects into an object array. The subform-variable is set to the object-array.

V14 needs an extra step. The object-array is to be transformed into a string (JSON Stringify array) and the subform-variable set to the resulting text. The other way around, subform calling masterform,  the textcontent of the subform-variable needs to be converted into text first. Inside the master form this text is to be parsed (JSON PARSE ARRAY). Next the objects get unpacked and array-rows set to the object-contents. This part – Object → Text → Object – can be omitted in V15, instead the subform-variable is already defined as an object. While building this system in V14, you are not procrastinating work for sometime later V15. Use the same code in V15 including those extra-transformations, the performance-hits are negligible.

Still wondering? Load this V14-database an find out, how it works.

WordPress comments attract lots of spam. Mail me your comments, I might attach them manually.