Struct [v2.1-alpha.22+]

class Struct extends Any

Struct is the base class for all structs.

Unlike Object, a struct's properties are limited to those defined by its base object (the Prototype of the struct's class). These are typically typed properties declared in a struct definition, but can include dynamic properties, methods and read-only value properties.

"Obj" is used below as a placeholder for any instance of the Struct class.

Instances of Struct are indirectly based on Struct.Prototype, which is based on Any.Prototype. In addition to the methods and properties inherited from Any, Structs have the following predefined methods and properties.

Table of Contents

Static Methods

Call

Creates a new Struct.

Obj := StructClass()
Obj := StructClass.Call()

StructClass must be a subclass of Struct. Subclasses can be created by a struct definition or at runtime.

At

Creates a boxed pointer, which behaves as an instance of StructClass.

Obj := StructClass.At(Address)

Parameters

Address

Type: Integer

The address of a struct of the type defined by StructClass.

Return Value

Type: Object

Remarks

StructClass must be a subclass of Struct.

See Boxed Pointer for further details.

Static Properties

Prototype

Gets the Prototype on which all instances of the struct class are based.

Proto := ClassObj.Prototype

See ClassObj.Prototype for details.

Ptr

Gets a class representing a pointer to a StructClass.

PtrClass := StructClass.Ptr

Type: Class

This is used with DllCall and typed properties.

See Pointers to Structs for further details.

__Item [v2.1-alpha.23+]

Gets a class representing a fixed-size array of StructClass elements.

ArrayClass := StructClass[Length]
ArrayClass := StructClass.__Item[Length]

Parameters

Name

Type: Integer

The length of the array type.

Return Value

Type: Class

The return value is a subclass of Struct.Array.

This is typically used with DllCall and typed properties.

Methods

__Ref

Retrieves a nested struct or virtual reference to a property.

Obj.__Ref(Name)

Parameters

Name

Type: String

The property's name.

Return Value

Type: Object

If the property is a nested struct, a reference to the struct is returned. The property corresponding to a nested struct can only be assigned a value if the struct defines a settable __Value property. The struct itself can also be used as a virtual reference in that case. An abstract data type typically implements both a getter and a setter, in which case the nested struct itself can only be retrieved via this method.

If the property is a pointer type or not a nested struct, a PropRef is created and returned.

Remarks

This method is normally called indirectly via the reference operator. For example, &Obj.Prop is equivalent to Obj.__Ref('Prop').

A virtual reference can be passed to a ByRef parameter in place of a variable reference.

Properties

Length

Gets the number of elements in a structured array.

ElementCount := Obj.Length

Type: Integer

This property applies to instances of fixed-size array classes such as Int32[4]. Accessing it on a struct which is not a structured array throws a PropertyError.

Ptr

Gets the address of the struct.

Address := Obj.Ptr

Type: Integer

The address of a struct is the same as the address of its first field (typed property).

Size

Gets the size of the struct in bytes.

Size := Obj.Size

Type: Integer