|
|
|
|
|
- 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 (Variable type) In french: Structure (Type de variable)
A structure is a custom type of data. A structure groups different types of elements. Remark: If you manipulate custom variables, it is advisable 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).
RefProduit is Structure
CodeF is int
CodePr is string fixed on 10
END
RefProduit is Structure
CodeF is int
CodePr is string fixed on 10
END
Fauteuil is RefProduit
RefProduit is Structure
CodeF is int
CodePr is string fixed on 10
END
Fauteuil is RefProduit
Fauteuil:CodeF = 7
Fauteuil:CodePr = "Meuble"
point3D is Structure
x is int
y is int
z is int
END
p1 is point3D = [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 structure. <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. Warning: "Is a structure" must be placed before "is a class".
- in a process, 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 member whose type is dynamic array:
The array dimensions must be defined (which means that the array must be allocated) before using the array. For example:
Struct is Structure
x1 is int
x2 is array dynamic
END
MaStruct is Struct
MaStruct:x2 = new array dynamic of 4,7 int
MaStruct: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. Please note that the copy is made from member to member: only members with the same name will be copied.. The members with different or non-existing names will be ignored. Example:
StructClientImport is Structure
Nom is string
Prénom is string
Société is string
Adresse is string
CP is string
Ville is string
END
StructClientInterne is Structure
Nom is string
Prénom is string
Société is string
Adresse is string
AdresseComp is string
CP is string
Ville is string
Pays is string
END
NouveauClient is StructClientImport
ClientEnCours is StructClientInterne
ClientEnCours = NouveauClient
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:
<Nom du membre> est un <Type du membre> [, Sérialise = <Vrai / Faux>] - Serialization and change of member name:
<Nom du membre> est un <Type du membre> [, Sérialise = <Nouveau nom>]
Example: Cl is Structure
MembreSérialisé is int
MembreNonSérialisé is string, serialize = false
MembreRenommé is int, serialize = "NouveauNomMembre"
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: <Nom de la procédure>(<Nom de la variable de type structure>) For example: RefProduit is Structure
CodeF is int
CodePr is string fixed on 10
END
Fauteuil is RefProduit
AfficheProduit(Fauteuil)
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:
STTouche is Structure
sTouche is string
nCodeAscii is int
END
tabTouches is array of STTouche
In most cases, content is added by using a variable of a type declared in the structure:
stUneTouche is STTouche
stUneTouche.sTouche = "A"
stUneTouche.nCodeAscii = Asc("A")
tabTouches.Ajoute(stUneTouche)
With the [ ] operator, you get better legibility:
tabTouches.Ajoute(["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 structure member cannot be restricted: all the members of a structure are public.
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|