- Declaring structures
- Type of structure members
- Declaring an array member in a structure
- Homonymic copy of a structure
- Serializing the members of a structure
- Which "advanced" types can be a member?
- Passing a structure as a parameter to a procedure
- Adding the content of a structure to an array of structures without using a variable of the structure
- Limits of a structure
- Differences between version 8 and version 9
Structure (Type of variable) In french: Structure (Type de variable)
A structure is a custom type of data. A structure groups different types of elements. Remark: If you are handling custom variables, we advise you to declare: - a structure type if several variables of this type are used in different processes of the project.
- a composite variable if a single variable of this type is used in your project (to pass parameters to an API for example).
// Declare a structure ProductRef is Structure SCode is int PdtCode is fixed string on 10 END
// Declare a structure variable ProductRef is Structure SCode is int PdtCode is fixed string on 10 END Armchair is ProductRef
// Handle a member of a structure variable ProductRef is Structure SCode is int PdtCode is fixed string on 10 END Armchair is ProductRef Armchair:SCode = 7 Armchair:PdtCode = "Furniture"
// Declare and initialize the members of a structure 3dPoint is Structure x is int y is int z is int END p1 is 3dPoint = [0, 0, 50]
Syntax
Declaring a structure Hide the details
<Structure name> is structure <Structure members> END
<Structure name>: Name of structure to declare <Structure members>: Declarations of variables found in the structure. These variables are called members of the composite variable. <END>: End of variable declaration.
Declaring a structure variable Hide the details
<Variable name> is <Structure name>
<Variable name>: Name of the structure variable to declare. <Structure name>: Name of a structure that was declared beforehand.
Handling a member of a structure variable Hide the details
<Name of structure variable>:<Name of structure member>
<Name of structure variable>: Name of the structure variable to use. <Name of structure member>: Name of the structure member to use. Remarks If a <Structure name> structure is declared: - in the project code, a <Structure name> variable can be declared in the entire project.
- in the declaration code of the global variables of a window, a <Structure name> variable can be declared in the window, in its controls and in its associated local procedures.
- in the opening code of a report, a <Structure name> variable can be declared in the report, in its controls and in the associated local procedures.
- in the declaration code of a class, a <Structure name> variable can be declared in the class and in its methods. Caution: "Is structure" must necessarily be positioned before "is class".
- in a process/i>, a <Structure name> variable can be declared in the process.
Type of structure members The members of a structure can have the following types: Any other type of data (composite variable, constant, ...) is forbidden. Declaring an array member in a structure Declaring a member whose type is simple array: The array dimensions are fixed when the array is declared. The array dimensions can be modified by Dimension.Declaring a dynamic array member: The array dimensions must be defined (which means that the array must be allocated) before using the array. For example:
// Declare a structure Struct is Structure x1 is int x2 is dynamic array // Declare the array END // Declare a structure variable MyStruct is Struct // Allocate the array MyStruct.x2 = new dynamic array of 4,7 int // Use the array MyStruct:x2[1,1] = 25
Homonymic copy of a structure The => operator is used to perform an homonymic copy of a structure variable. This homonymic copy can also be performed by using the = operator. Caution, the copy is performed member to member: only the members with same names will be copied. The members with different or non-existing names will be ignored. Example:
// Declare a structure StructImportCustomer is Structure LastName is string FirstName is string Company is string Address is string ZC is string City is string END StructInternalCustomer is Structure LastName is string FirstName is string Company is string Address is string FullAddress is string ZC is string City is string Country is string END NewCustomer is StructImportCustomer CurrentCustomer is StructInternalCustomer CurrentCustomer = NewCustomer // the FullAddress and Country members are not filled
Serializing the members of a structure By default, all the members of a structure are serialized. You have the ability to precisely manage the serialization of each member of a structure: - by specifying the member that will be serialized during the call to Serialize.
This operation can be performed on all types of serialization (WXML, JSON, binary). - by changing the name of the member during the serialization with Serialize.
This operation can be performed during a binary serialization only.
This management of serialization is performed by using the following syntax: - Serialization (or not) of a member:
<Member name> is <Type of member> [, Serialize = <True/False>]
- Serialization and change of member name:
<Member name> is <Type of member> [, Serialize = <New name>]
Example:
Cl is Structure // Serialized member SerializedMember is int // Non-serialized member NonSerializedMember is string, Serialize = false // Member renamed during the serialization RenamedMember is int, Serialize = "NewMemberName" END
Which "advanced" types can be a member? An "advanced" variable can be a member of another "advanced" variable. The table below presents the different combinations: | | | | |  | Composite variable | Structure | Class | Array |
---|
Composite variable | No | No | No | No | Structure | Yes | Yes | Yes | Yes | Class | Yes | Yes | Yes | Yes | Array | Yes | Yes | Yes | No |
Passing a structure as a parameter to a procedure A "structure" variable can be passed as a parameter to a procedure. To do so, use the following syntax:
<Procedure name>(<Name of structure variable>)
For example:
ProductRef is Structure SCode is int PdtCode is fixed string on 10 END Armchair is ProductRef // Call the DisplayProduct procedure DisplayProduct(Armchair)
Adding the content of a structure to an array of structures without using a variable of the structure If you are using an array of structures with few members, it may be easier to directly add a structure by using the [ ] operator (square brackets). For example, for the following structure:
// Structure to store a letter and its ASCII code STKey is Structure sKey is string nAsciiCode is int END // Array of structures arrKeys is array of STKey
In most cases, content is added by using a variable of a type declared in the structure:
// Temporary structure for the addition stAKey is STKey // Stores the letter A stAKey.sKey = "A" stAKey.nAsciiCode = Asc("A") arrKeys.Add(stAKey)
With the [ ] operator, you get better legibility:
// Stores the letter A arrKeys.Add(["A", Asc("A")])
Limits of a structure - The inheritance of structure is not allowed: a structure cannot inherit from another structure.
- The access to a member of a structure cannot be restricted: all the members of a structure are public.
This page is also available for…
|