Struct.fieldName(Int32) Method

Definition

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

public:
 virtual System::String ^ fieldName(int _index);
public virtual string fieldName (int _index);
abstract member fieldName : int -> string
override this.fieldName : int -> string
Public Overridable Function fieldName (_index As Integer) As String

Parameters

_index
Int32

The position in the struct at which you want to retrieve the item name.

Returns

The name of the item at the position specified by index.

Remarks

If index is not found, an empty string is returned.

The following example creates a struct from a container and then uses the Struct.fields method to iterate through the contents of the container. The fieldName method is used to test the name of each item in the struct, and a specific action is run depending on the value of this name.

boolean unpack(container packed) 
{ 
    Struct      unpackedProperties; 
    container   structCon; 
    Counter     i; 
    [#currentList,structCon] = packed; 
    unpackedProperties = Struct::create(structCon); 
    for (i=1;i<=unpackedProperties.fields();i++) 
    { 
        switch (unpackedProperties.fieldName(i)) 
        { 
            case #closedOk: 
                break; 
            case #PropertyCaption: 
                if (! dialogForm  
                    || dialogForm  
                    && ! dialogForm.form().design().caption()) 
                    this.caption(unpackedProperties.valueIndex(i)); 
                break; 
            case #dialogFormname: 
                // Do nothing 
                break; 
            case #PropertyAlwaysOnTop: 
                this.alwaysOnTop(unpackedProperties.valueIndex(i)); 
                break; 
            case #PropertyWindowType: 
                this.windowType(unpackedProperties.valueIndex(i)); 
                break; 
            case #defaultButton: 
                this.defaultButton(unpackedProperties.valueIndex(i)); 
                break; 
            default: 
                throw error(strfmt( 
                    "@SYS67326",unpackedProperties.fieldName(i), 
                     classId2Name(classidget(this)))); 
        } 
    } 
    return true; 
}

Applies to