List box where property of object equals column - one object per row

We are just starting an upgrade to v17 from v13 (I know, big jump). There are several corners in our code that could benefit from being refactored away from a group of coordinated arrays into an array (or collection, or whatever) of objects where each property contains an item of data from the coordinated arrays.

E.g.

ARRAY TEXT(atFirstName;3)
ARRAY TEXT(atLastName;3)
ARRAY LONGINT(alAge;3)
atFirstName{1}:=“Joe”
atLastName{1}:=“Smith”
alAge{1}:=35

Becomes:

ARRAY OBECT(aobjPeople;3)
C_OBJECT($o1;$o2;$o3)
OB SET($o1;“FirstName”;“Joe”;“LastName”;“Smith”;“Age”;35)

What I’m wondering is whether there’s some way to setup a list box such that any one object becomes one row of data. For example, my list box might look like this:

| First Name | Last Name | Age |
| Joe | Smith | 35 |

Using notation along the lines of:

| aobjPeople.FirstName | aobjPeople.LastName | aobjPeople.Age |

The only examples I see for using objects in the documentation involve using coordinated arrays of objects where the first object in the first array is the first cell in the first column, first array second object is second cell first column, and so on. In essence, I’m trying to figure out if there’s a way to use objects (or collections, or whatever) such that they are horizontal, not vertical.

Is this possible?

Never mind, I figured it out myself. The answer was hiding in a corner of the documentation I didn’t at first expect, namely “LISTBOX INSERT COLUMN FORMULA”.

The secret is to create a list box where the data type is “Collection or entity selection” (in my case the collection name is “Persons”). My three columns have the formula “This.FirstName”, “This.LastName”, and “This.Age”. The following throw-away code is in form load event:

C_OBJECT($obj0;$obj1;$obj2)
OB SET($obj0;“FirstName”;“Tom”;“LastName”;“Smith”;“Age”;25)
OB SET($obj1;“FirstName”;“Bob”;“LastName”;“Jones”;“Age”;31)
OB SET($obj2;“FirstName”;“Ralph”;“LastName”;“Thompson”;“Age”;44)
C_COLLECTION(Persons) // Remember, my collection name is “Persons” in the design view
Persons:=New collection($obj0;$obj1;$obj2)

That is sufficient for me to understand what I need. :smiley:

Sometimes one can’t find the answer until one asks it out loud…

Hello…
in you case you must have a collection of objects rather than many objects.
Once you got them in a collection, you can une a listbox to display items of this collection (one item per row) using the new function “This”

This.FirstName / This.LastName / This.Age (etc.)

This also works with entity selections (see DS command)

Many examples are available on the Blog !
(https://blog.4d.com)

Hope this helps

Roland

Thank you, yes. In this particular case I’m going to have many objects because a great deal of what the object shows is calculated rather than stored. The idea is that the user has a window which allows them to input a batch of transactions, and the user needs to be able to go back and forth between the list of transactions and the changes any one of those transactions will produce before committing to the full list of changes. This is done through a dialog that looks a bit like a input form, but in fact does not have an underlying selection.

Currently the values are stored in a large number of synchronized process arrays, but it’s ugly, slow, and brittle. Objects will make it much easier because I won’t have the problem of losing synchronization between related arrays, everything will all be encapsulated in one object.

Not sure yet whether ORDA will work with this cleanly or not, considering that probably 80% of my main object does not persist. I still need to do some thinking.

Anyway, thank you for your response!