Struct Class

Definition

A struct holds several values of any X++ type, to group the information about a specific entity.

public ref class Struct : Microsoft::Dynamics::Ax::Xpp::XppObjectBase
public class Struct : Microsoft.Dynamics.Ax.Xpp.XppObjectBase
type Struct = class
    inherit XppObjectBase
Public Class Struct
Inherits XppObjectBase
Inheritance
Microsoft.Dynamics.AX.KernelInterop.ProxyBase
Struct

Remarks

A struct (short for structure) is an entity that can hold several values of any X++ type. Structs are used to group information about a specific entity. For example, you might want to store information about a customer's name, age and address and then treat this compound information as one item. The items in a struct are specified by a data type and a name. Items are added when the struct is created by using the new method, or they are created after the struct has been created by using the add method. If you add an item by using the add method, you specify the value for the item at the same time, and the data type is inferred from this value. If you add an item during the instantiation of the struct, you need to use the value or the valueIndex method to assign a value to it. 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. The items in a struct are arranged in alphabetical order of the item names. The fields in a struct can be traversed by using the fields, fieldName, and fieldType methods. Structs can be packed into containers and later restored by using the Struct::create method. Structs have some similarities to X++ containers. However, a container is a value type and is built into the X++ language. You can create nested containers, but you cannot create nested structs. X++ classes can store information in much the same way as structs. But although classes can supply methods to manipulate the data, no such facility is provided for structs, and there is no concept of overriding or extension. Classes can only be created in the AOT, but structs exist solely in the context of the code in which they are created. Class member variables are private to the class, so accessor functions must be coded for them for the values to be used from outside the class. The items within a struct are publicly accessible.

The following example creates a struct with two items and then assigns values to those items. A new item is then added by using the Struct.add method; the data type of the item is inferred from the value assigned to it. The struct is then packed into a container and used to create a new struct, a copy of the original struct.

{ 
    Struct s = new struct ("int age; str name"); 
    Struct copy; 
    container c; 
    int i; 
    // Add values to the items 
    s.value("age", 25); 
    s.value("name", "Jane Dow"); 
  // Add a new item; data type is inferred from value 
    s.add("Shoesize", 45); 
    // Print the definition of the struct 
    print s.definitionString(); 
    // Prints the type and name of all items in the struct 
    for (i =  1;   i <= s.fields();i++) 
    { 
         print s.fieldType(i), " ", s.fieldName(i); 
    }  
    // Pack the struct into a container and restore it into copy 
    c = s.pack(); 
    copy = Struct::create(c); 
    print copy.definitionString(); 
    pause; 
}

Constructors

Struct()
Struct(Object[])

Fields

kernelClass (Inherited from XppObjectBase)

Properties

AxClassId
GlobalType

Methods

__shouldCallNew(Type) (Inherited from XppObjectBase)
add(String, Object)

Adds a new item to the struct and assigns the specified value to it.

addXppProxyReference(Type, Object) (Inherited from XppObjectBase)
Call(String, Object[], Type[], Object[]) (Inherited from XppObjectBase)
cancelTimeOut(Int32) (Inherited from XppObjectBase)
create(Object[])

Creates a struct from a container that is obtained from a prior call to Struct.pack.

createFromXML(XppObjectBase)
createKernelClass(Object[], Type[], Object[]) (Inherited from XppObjectBase)
definitionString()

Returns a description of the names and types of the elements in the struct.

equal(Struct, Struct)

Determines whether two structs are equal.

equal(XppObjectBase) (Inherited from XppObjectBase)
exists(String)

Determines whether a particular item exists in a struct.

fieldName(Int32)

Returns the name of the item in the struct at the specified position.

fields()

Returns the number of items in the struct.

fieldType(Int32)

Returns the data type of the item in the struct at the specified position.

finalize() (Inherited from XppObjectBase)
GetIntPtr()
GetKernelInstanceUniqueId() (Inherited from XppObjectBase)
getTimeOutTimerHandle() (Inherited from XppObjectBase)
getXppProxyReference(Type) (Inherited from XppObjectBase)
handle()
index(String)

Calculates the position of an item in the struct based on its name.

IsManagedValid()
kernelhandle()
KernelInstanceDisposed() (Inherited from XppObjectBase)
MakeReflectionCall(String, Object[]) (Inherited from XppObjectBase)
merge(Struct, Struct)

Combines two structs to create a new struct.

newmethod() (Inherited from XppObjectBase)
newmethod(Object[])

Creates a struct.

notify() (Inherited from XppObjectBase)
notifyAll() (Inherited from XppObjectBase)
objectOnServer()
Obsolete.
(Inherited from XppObjectBase)
pack()

Serializes the current instance of the Struct class.

remove(String)

Removes an item from a struct.

setTimeOut(String, Int32, Boolean)
Obsolete.
(Inherited from XppObjectBase)
setTimeOut(String, Int32)
Obsolete.
(Inherited from XppObjectBase)
ToString()

Returns a string that describes the contents of the struct.

usageCount() (Inherited from XppObjectBase)
value(String, Object)
value(String)

Gets or sets the value for a specified item in a struct.

valueImage(Int32)

Returns a string that describes the value of the item at a particular position in the struct.

valueIndex(Int32, Object)
valueIndex(Int32)

Gets or sets the value of the item at a specified position in a struct.

VerifyKernelClass() (Inherited from XppObjectBase)
wait() (Inherited from XppObjectBase)
Xml()

Returns an XML string that represents the current object.

Xml(Int32)

Applies to