Udostępnij za pośrednictwem


Anytype

Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012

The anytype data type is a placeholder for any data type. Variables of type should only be used as arguments and return values.

If anytype is used as a variable, you must assign a value to it before it can be used or you will get a run-time error. After you have assigned a value to it, you cannot convert it to another data type.

Range

The range of an anytype variable depends on the value first assigned to it. For example, if an integer is assigned, the range of the variable will then be [-2.147.483.647 ; 2.147.483.647].

Declaring anytype Variables

anytype declaration

=

anytype Variable { , Variable } ;

variable

=

identifier [ option ]

option

=

arrayoptions | initialization

Automatic Conversions

The anytype data types can be automatically converted to dates, enums, integers, reals, strings, guids, int64s, extended data types (records), classes, and containers by assigning a value to the type. For example:

    anytype a;
    ;
    a = "text";  // Assigns a string literal

However, after you have converted the anytype data type, you cannot then change it to another data type.

Using anytype Variables

You can use anytype variables in expressions. You can also use them in the same way that you can use the data type that you convert them to. For example, if you assign an integer, you can then apply relational and arithmetic operators to the variable.

However, anytype is usually used as arguments and return types. For example:

    public static str range(anytype _from, anytype _to)
    {
        return queryValue(_from) + '..' + queryValue(_to);
    }

and

    void put(int position, anytype data)
    {
        record = conpoke(record, position, data);
    }

Overview of anytype Variables

Keyword

anytype

Size

Depends on conversion type

Scope of data type

Depends on conversion type

Default value

Depends on conversion type

Implicit conversions

Automatically converted to dates, enums, integers, reals, strings, extended data types (records), classes, and containers

Explicit conversions

any2date, any2enum, any2int, any2real, any2str

See also

Data Types in X++

Variables

Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.