Structures differ from classes in several important ways:
Structures are value types.
All structure types implicitly inherit from the System.ValueType class.
Assignment to a variable of a structure type creates a copy of the value being assigned.
The default value of a structure is the value produced by setting all value type fields to their default value and all reference type fields to Null.
Boxing and unboxing operations are used to convert between a structure and Object type.
The meaning of Self for structures is different from classes.
Field declarations for a structure are not permitted to include value initializers.
A parameterless instance constructor cannot be declared in a structure.
Assignment to a variable of a structure type creates a copy of the value being assigned. This differs from assignment to a variable of a reference type, which copies the reference but not the value itself.
Similar to an assignment, when a structure is passed as a value parameter or returned as the result of a function member, a copy of the structure is created. A structure may be passed by reference using reference or output parameters.
When a structure property is used in the left part of an assignment statement, the instance expression associated with the property must be classified as a variable. If the instance expression is classified as a value, a compile error occurs.
Struct UserStructure
Public Title: string;
Public Param1: integer;
Public Param2: double;
Constructor Create(STitle: string; Param1Value: integer; Param2Value: double);
Begin
Title := STitle;
Param1 := Param1Value;
Param2 := Param2Value;
End Constructor;
End Struct;
Sub Test();
Var
StructObj, StructObj1: UserStructure;
Begin
StructObj := New UserStructure("User structure", 100, 3.14);
StructObj1 := StructObj;
StructObj1.Title := "Copy of a structure with modified parameter values";
StructObj1.Param1 := 200;
StructObj1.Param2 := 2.7;
End Sub;
See also: