4D v14

Arrays, pop-ups, list boxes

Home

 
4D v14
Arrays, pop-ups, list boxes

Arrays, pop-ups, list boxes    


 

 

In addition to the manipulations explained in the video, you should also note that:

Arrays are one of the indispensable features in 4D.

Practical, unlimited, dynamic, one- or two-dimensional, they are a “space” in memory that can be displayed in forms using objects (pop-ups, combo boxes, list boxes, scrollable areas, etc.

We’ve already discussed the concept and use of single-value variables. An array is a multi-valued variable that we can read or write each of its elements.

We define an array by setting the number of lines it contains and its type. Here’s a chart showing the different stages of a variable and an array’s life cycle:

StepSimple variableArray variable
InitializationC_TEXT(vText)ARRAY TEXT(ArrayText;10) `10 rows
ValorizationvText:="Tascher de la Pagerie"ArrayText{1}:="De Beauharnais" `row 1
ArrayText{2}:="Barras" `row 2
ArrayText{3}:="Bonaparte" `row 3
...
Usage$NumChar:=Length(vText)$Amant:=ArrayText{1}
Erase contentCLEAR VARIABLE(vText)ARRAY TEXT(ArrayText;0)
(behavior is different between an interpreted and compiled
application, refer to 4D documentation)
View on a formGive the variable name to a variable type objectGive the name of the variable to a scrollable area/pop-up menu type object
TypesInteger, Long integer, Numeric, Alpha, Text, Boolean, Date, Time, Picture, BLOB, pointersIdentical to variable types except Time and BLOB

As you can see, there are a number of similarities between the two.

The name of the array is sometimes used with braces { }, sometimes by itself. In this case, it’s a variable (long integer) automatically created by 4D.

This variable, associated with the array, serves as an array index (row number). It’s through this variable that we can learn which row the user selected or force selection of a specific row in the pop-up menu.

This is what you’ll often see this concise syntax written in database:

 [INTERVENTIONS]Object:=ObjectsArr{ObjectsArr}

that we can decrypt as follows: "Object := array content {at the chosen row}"
You’ll also find, though more concise and a lot more generic, this syntax that uses the Self command (pointer towards the object whose method is being executed):

 [INTERVENTIONS]Object:=Self->{Self->}

Regardless of the syntax used, the behavior is the same.

In 4D, a tab is an unique object with several titles (values). It's an example of an interface object that can represent an array.

Usually, we put tabs on page 0 of the form (see the section that covers this point).

You'll notice that arrays become useful quite quickly; in fact, they soon become a necessity.

An array only contains items of the same type. You cannot have an array with an Alpha element, a Date element and then a third Time element. In thiscase, you can use an array of pointers that could point to variables of different types.

As mentioned in the lesson on pointers, you can combine pointers and arrays to get “pointer arrays”.

You can also consider a List box to be a series of connected arrays (of the same X dimension).

It's an object that groups together and synchronizes one or more arrays.

In a list box, you can configure:

  • the list box itself
  • each column header
  • and each column

In all, if your list box has X columns, you have 2X+1 objects (X columns, X headers + 1 list box).

List boxes let you:

  • enter data
  • sort and move rows and columns
  • display alternating colors
  • have a hierarchical display
  • add totals to footers
  • A list box can be synchronized with arrays as we did here or with fields of the current selection (or a named selection) of a table
  • and so on.

Keep in mind that the list box synchronizes its columns; it takes the smallest number of rows from the arrays that make it up.

This is important to remember because you could have arrays that are filled with data and still end up with an empty list box if one of its arrays is empty.

 
 

 
PROPERTIES 

Product: 4D
Theme: Arrays, pop-ups, list boxes

 
ARTICLE USAGE

Self-training ( 4D v13)
Self-training ( 4D v14)