編集

次の方法で共有


Option Data type

Version: Available or changed with runtime version 1.0.

Denotes an option value. In the code snippet below, you can see how the Option data type is declared.

Syntax example

procedure HelloWithOptions(OptionParameter : Option Alpha, "Bra-vo")
    var 
        OptionVariable : Option C, "or D";
    begin
        Message('%1',OptionParameter::Alpha);
        Message('%1',OptionVariable::C);
    end;

Note

It is not possible to reference the members of the OptionParameter from outside the body of the procedure.

Remarks

In the OptionString Property of the field or variable, you can enter the option values as a comma-separated list. The Option type is a zero-based enumerator type, which means that the option values are assigned to sequential numbers, starting with 0. You can convert option data types to integers.

Example 1

The following code sample shows how to define an option field in a table.

field(0; PreferredContactMethodCode; Option)
{
    Caption = 'Preferred Method of Contact';
    // The OptionMembers property must be defined on an option field. It specifies which values can the field take.
    OptionMembers = Any,Email,Phone,Fax,Mail;
}

Example 2

This example shows how you can use the value of an option field as a constant in your AL code.

PurchHeaderRec."Document Type" := PurchHeaderRec."Document Type"::Invoice;   

Get Started with AL
Developing Extensions