Struct.new Method

Creates a struct.

Syntax

public void new( specifier)

Run On

Called

Parameters

  • specifier
    Type: [T:]
    One or more pairs that specify the data type of an item followed by the name of the item as a string.

Remarks

The data type of the item can be specified using the name of a primitive data type or by using the system enum. The items in a struct can be of any of the data types found in the Types system enum, including: string, integer, real, date, container, record, and class.

You can create a copy of a struct by using the Struct.definitionString method to create a new struct, as illustrated in the example below.

After you have created a struct, you can add new items using the Struct.add method and set the value of items in the struct by using the Struct.value or Struct.valueIndex method.

Examples

The following example creates two structs with the same definition and then adds 2 values and an additional item and value to one of them (s1). This struct is then copied to create a new struct by using the Struct.definitionString method.

{ 
    Struct s1, s2, s3; 
     
    // The two constructors below create the same struct 
    s1 = new Struct(Types::Integer, "age", Types::String, "name"); 
    s2 = new Struct ("int age; str name"); 
     
    // Print the definitions 
    print s1.definitionString(); 
    print s2.definitionString(); 
    s1.value("age", 25); 
    s1.value("name", "Jane Dow"); 
  
    // Add a field at runtime 
    s1.add("Shoesize", 45); 
     
    print s1.definitionString(); 
    print s1.toString(); 
  
    // Create a container with age, name and shoesize, 
    // using definitionString 
    s3 = new struct(s1.definitionString()); 
     
    print s3.definitionString(); 
    pause; 
}

See Also

Struct Class

Struct.add Method

Struct.value Method

Struct.valueIndex Method

Struct.definitionString Method