Structures

Syntax

Structure <name> 
  ...
EndStructure 

Description

Structure is useful to define user type, and access some OS memory areas. Structures can be used to enable faster and easier handling of big data files. It could be useful as you can group into the same object the informations which are common. Structures are accessed with the \ option. Structures can be nested. Statics arrays are supported inside structures.

Example 1 :

Structure Person
  Name.s
  ForName.s 
  Age.w 
EndStructure

Dim MyFriends.Person(100)

; Here the position '0' of the array MyFriend()
; will contain one person and it's own informations

MyFriends(0)\Name = "Andersson"
MyFriends(0)\Forname = "Richard" 
MyFriends(0)\Age = 32


Example 2 : A more complex structure (Nested and static array)

Structure Window
  *NextWindow.Window  ; Points to another window object
  x.w 
  y.w
  Name.s[10]  ; 10 Names available 
EndStructure


Syntax

StructureUnion
  Field1.Type
  Field2.Type
  ...
EndStructureUnion
  

Description

Structure union are only useful for advanced programmers which want to save some memory by sharing some fields inside the same structure. It's like the 'union' keyword in C/C++.

Example :

Structure Type
  Name$
  StructureUnion
    Long.l      ; Each field (Long, Float and String) resides at the
    Float.f     ; place in memory.
    String.s    ;
  EndStructureUnion
EndStructure

Syntax

size = SizeOf(Type)

Description

The SizeOf command can be used to find out the size of any complex Structure (it does not work on the simple built-in types such as word and float). This can be useful in many areas such as calculating memory requirements for operations, using API commands, etc.

Example :

Structure Person
  Name.s
  ForName.s 
  Age.w 
EndStructure

If OpenConsole()

PrintN("The size of my friend is "+Str(Sizeof(Person))+" bytes")
Input()
CloseConsole()
EndIf
End