Static and Instance Methods

When a method declaration includes the Shared modifier, this method is said to be a static method. When no Shared modifier is present, the method is said to be an instance method.

A static method does not operate on a specific instance, and it is a compile error to use the Self structure in a static method.

An instance method operates on a given instance of a class, and that instance can be obtained using the Self structure.

The differences between static and instance members are described further in the Static and Instance Members section.

E xample

Class SharedMethod
    Public Shared i: integer;
    Public Shared o: object;
    Shared b: boolean;
    
    Public Shared Sub Reset();
    Begin
        i := 0;
        o := Null;
    End Sub;
    
    Public Shared Function TestObject(): boolean;
    Begin
        If (i <> 0And (o <> NullThen
            b := True;
        Else
            b := False;
        End If;
        Return b;
    End Function;
    
    Public Sub Execute();
    Begin
        
    End Sub Execute;
End Class;

Sub Test();
Var
    Obj: SharedMethod = New SharedMethod();
Begin
    SharedMethod.Reset();
    ...
    SharedMethod.i := //Set value
    SharedMethod.o := //Set value
    ...
    If SharedMethod.TestObject() Then
        //Operations if the function returns  True
    Else
        //Operations if the function returns  False
    End If;
    Obj.Execute();
End Sub;

See also:

Methods