PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • 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 in parameter to a procedure
  • Adding the content of a structure into an array of structures without using a variable of this structure
  • Limits of a structure
  • Differences between version 8 and version 9
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
A structure is a custom type of data. A structure groups different types of elements.
Note: 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).
Versions 16 and later
Universal Windows 10 App This feature is available for the Windows Phone applications.
New in version 16
Universal Windows 10 App This feature is available for the Windows Phone applications.
Universal Windows 10 App This feature is available for the Windows Phone applications.
Versions 17 and later
iPhone/iPad This feature is available for the iPhone/iPad applications.
New in version 17
iPhone/iPad This feature is available for the iPhone/iPad applications.
iPhone/iPad This feature is available for the iPhone/iPad applications.
Versions 18 and later
Universal Windows 10 App This feature is available in Windows Store apps mode.
Android Widget This feature is available in Android Widget mode.
New in version 18
Universal Windows 10 App This feature is available in Windows Store apps mode.
Android Widget This feature is available in Android Widget mode.
Universal Windows 10 App This feature is available in Windows Store apps mode.
Android Widget This feature is available in Android Widget mode.
Versions 20 and later
WEBDEV - Browser code This feature is available in browser code.
New in version 20
WEBDEV - Browser code This feature is available in browser code.
WEBDEV - Browser code This feature is available in browser code.
Versions 21 and later
Universal Windows 10 App This feature is now available in Universal Windows 10 App mode.
Apple Watch This feature is now available in Apple Watch mode.
New in version 21
Universal Windows 10 App This feature is now available in Universal Windows 10 App mode.
Apple Watch This feature is now available in Apple Watch mode.
Universal Windows 10 App This feature is now available in Universal Windows 10 App mode.
Apple Watch This feature is now available in Apple Watch mode.
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.
Versions 19 and later
When declaring the members of the structure, you have the ability to specify the serialization parameters of these members. See "Serializing the members of a structure" for more details.
New in version 19
When declaring the members of the structure, you have the ability to specify the serialization parameters of these members. See "Serializing the members of a structure" for more details.
When declaring the members of the structure, you have the ability to specify the serialization parameters of these members. See "Serializing the members of a structure" for more details.
<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 global variables of a window, a <Structure name> variable can be declared in this window, in the controls of this window and in the associated local procedures.
  • in the opening code of a report, a <Structure name> variable can be declared in this report, in the controls of this report and in the associated local procedures.
  • in the declaration code of a class, a <Structure name> variable can be declared in this class and in the methods of this class. Caution: "Is structure" must necessarily be positioned before "is class".
  • in a process, a <Structure name> variable can be declared in this process.
JavaPHP The structure must be declared in the declaration process of global variables (of a window, page or set of procedures).
Versions 20 and later
WEBDEV - Server codeWEBDEV - Browser code Notes:
  • 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 made of simple types: string, integer, real, boolean, date and time.
New in version 20
WEBDEV - Server codeWEBDEV - Browser code Notes:
  • 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 made of simple types: string, integer, real, boolean, date and time.
WEBDEV - Server codeWEBDEV - Browser code Notes:
  • 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 made 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.
Versions 20 and later
WEBDEV - Browser code A structure declared in browser code must be made of simple types: string, integer, real, boolean, date and time.
New in version 20
WEBDEV - Browser code A structure declared in browser code must be made of simple types: string, integer, real, boolean, date and time.
WEBDEV - Browser code A structure declared in browser code must be made 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 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.
Versions 22 and later
This homonymic copy can also be performed by using the = operator.
New in version 22
This homonymic copy can also be performed by using the = operator.
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
Versions 19 and later

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 member name during the serialization by 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
New in version 19

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 member name during the serialization by 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

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 member name during the serialization by 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 variableStructureClassArray
Composite variableNoNoNoNo
StructureYesYesYesYes
ClassYesYesYesYes
ArrayYesYesYesNo

Passing a structure in parameter to a procedure

A "structure" variable can be passed in 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 into an array of structures without using a variable of this 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, the addition is performed by using a variable of structure type:
// 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.
WINDEVWEBDEV - Server codeWindows MobileJava

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