Show contents 

Fore Language Guide > Variables

Variables

Variable is a code element, which value can change during program execution. A variable type is set at declaration, in the future the variable may take values only with the specified type of compatible type.

Variables are used in a program to store and transfer data inside the program, they can also change their values during code execution. Variable description starts with the Var keyword followed by a sequence of variable definitions. Variables can be declared on namespace level, in procedures/functions and properties. In classes fields are used as variables.

Define a variable name (identifier) and type to describe a variable. A class, interface or enumerable type can be specified as a variable type. A colon is used to separate a name and type. A semicolon is used to end the variable declaration and description. Variables of one type may be listed via a comma before their type definition. Variable description ends when the next block or structure begins.

A variable may store a specific value or a reference to a value. A variable exists while the code, in which it is defined, is being executed:

Var
    <identifier>: <type>;

Example

// Variable in global namespace
Var global_A: Integer = 1000;

Namespace A
    // Variable in the  A namespace
    Var namespace_A: Integer = 100;

    Class CTest: Object
        // Variable in class
        class_A: Integer = 10;

        Public Sub Test;
        // Variable in procedure
        Var
            sub_A: Integer = 1;
        Begin
            Debug.WriteLine(global_A);
            Debug.WriteLine(namespace_A);
            Debug.WriteLine(class_A);
            // Change property value, at which field value changes
            VarValue := 500;
            Debug.WriteLine(class_A);
            Debug.WriteLine(VarValue);
            Debug.WriteLine(sub_A);
        End Sub Test;

        Public Property VarValue: Integer
            Get
            // Variable in the Get block of the property
            Var
                temp: Integer = 10;
            Begin
                Return class_A + temp;
            End Get
            Set
            // Variable in the Set block of the property
            Var
                temp: Integer = -10;
            Begin
                class_A := Value + temp;
            End Set
        End Property VarValue;

    End Class CTest;
End Namespace A;

Sub Main;
Var
    Obj: A.CTest;
Begin
    Obj := New A.CTest.Create;
    Obj.Test;
End Sub Main;

See also:

Fore Language Guide | Constants