ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage syntax / Declaring variables
  • 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
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
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).
Example
// Déclarer une structure
RefProduit is Structure
	CodeF is int
	CodePr is string fixed on 10
END
// Déclarer une variable de type structure
RefProduit is Structure
	CodeF is int
	CodePr is string fixed on 10
END
Fauteuil is RefProduit
// Manipuler un membre d'une variable de type structure
RefProduit is Structure
	CodeF is int
	CodePr is string fixed on 10
END
Fauteuil is RefProduit
Fauteuil:CodeF = 7
Fauteuil:CodePr = "Meuble"
// Déclarer et initialiser les membres d'une structure
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.
When declaring the members of the structure, you have the ability to specify the serialization parameters of these members. For more details, see "Serializing the members of a 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.
The members of a structure variable can be assigned via the multiple assignment.
Remarks

Declaring structures

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.
JavaPHP The structure must be declared in the declaration process of global variables (of a window, a page or a set of procedures).
WEBDEV - Server codeWEBDEV - Browser code Remarks:
  • A structure variable can be declared in browser code from a structure declared in server code or in browser code.
  • If a structure variable is declared in browser code from a structure declared in server code, the server structure must be composed of simple types: string, integer, real, Boolean, date and time..

Type of structure members

The members of a structure can have the following types:
Any other type of data (composite variable, constant, ...) is forbidden.
WEBDEV - Browser code A structure declared in browser code must be composed of simple types: string, integer, real, Boolean, date and time..

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:
    // Déclaration d'une structure
    Struct is Structure
    	x1 is int
    	x2 is array dynamic // Déclaration du tableau
    END
     
    // Déclaration d'une variable de type structure
    MaStruct is Struct
     
    // Allocation du tableau
    MaStruct:x2 = new array dynamic of 4,7 int
    // Utilisation du tableau
    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:
// Déclaration d'une structure
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 // les membres AdresseComp, Pays se seront pas renseignés

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
	// Membre sérialisé
	MembreSérialisé is int 
	// Membre non sérialisé
	MembreNonSérialisé is string, serialize = false  
	// Membre renommé lors de la sérialisation
	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 variableStructureClassArray
Composite variableNoNoNoNo
StructureYesYesYesYes
ClassYesYesYesYes
ArrayYesYesYesNo

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
 
// Appel de la procédure AfficheProduit
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:
// Structure pour mémoriser une lettre et son code ASCII
STTouche is Structure
	sTouche is string
	nCodeAscii is int
END
// Tableau de structures
tabTouches is array of STTouche

In most cases, content is added by using a variable of a type declared in the structure:
// Structure temporaire pour l'ajout
stUneTouche is STTouche
// Mémorise la lettre A
stUneTouche.sTouche = "A"
stUneTouche.nCodeAscii = Asc("A")
tabTouches.Ajoute(stUneTouche)

With the [ ] operator, you get better legibility:
// Mémorise la lettre A
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.
WINDEVWEBDEV - Server codeJava

Differences between version 8 and version 9

A structure containing a character member has not the same behavior as in the earlier versions. Indeed, the characters were coded on 1 byte in version 8 and on 2 bytes in version 9.
We recommend that you use the "1-byte integer" type.
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 09/24/2024

Send a report | Local help