$ ClassDeclaration = CLASS ident ":" BaseClass [{“, ImplInterface”}]
MemberList
END CLASS ident ";"
$ BaseClass = qualident
$ ImplInterface = qualident
$ MemberList = [ MemberDeclaration { MemberDeclaration }]
$ MemberDeclaration = ( ConstDeclaration | FieldDeclaration | MethodDeclaration | PropertyDeclarations | ConstructorDeclaration )
$ ConstDeclaration = CONST ConstEntry
$ FieldDeclaration = [ SHARED ] ( IdentList ":" ClassType ) | ( ident ":" ClassType ["=" ConstExpression ] ) ";"
$ MethodDeclaration = ( [ SHARED ] | [ FINAL ] ) ProcedureDeclaration
$ ConstructorDeclaration = ConstructorHeading ";" ConstructorBody
$ ConstructorHeading = CONSTRUCTOR ident “(“ [FormalParameters] “)”
$ ConstructorBody = BEGIN StatementSequence
END CONSTRUCTOR ident ";"
$EventDeclaration = EVENT ident ":" EventType
$EventType = qualident
The Fore language allows custom classes to be described and used in applications.
To determine custom classes, they should be inherited from a class. As a parent class, a basic class can be used, as well as an already defined custom class. Generally, a class is inherited from Object. By default, a class has the Private access modifier. A class may contain fields, properties and procedures (or so called methods). To call the fields, properties or methods of the object instance of the class, the syntax is used, which requires to specify:
<object name>.<field name>
or:
<object name>.<property name>
or:
<object name>.<method name>.
Calling the fields of the object is similar to calling variables; calling the methods is similar to calling procedures.
The class can implement a number of interfaces. This means that a class must contain implementation of all the members described in interfaces.
The class prior description is absent. Any class may be used if it is described in this unit or in any of the imported units. In this case any class parent must be determined before it would be inherited by the descendant classes.
The CONSTRUCTOR (Create) method is a standard one. Use the NEW statement to create a new object and call the Create method. The method is used to initialize an object. The method can be called for the existing object, in this case only method code will be executed (no memory will be used and no object fields will be initialized). All objects will be deleted automatically if there are no object links.
A method body may contain the INHERITED call, which will call the parent class method.
$ inheritcall = INHERITED ProcedureCall
To get a reference to the object, for which this method is called, within the class method, use the Self identifier. The predefined Self identifier is relevant only for class methods, attempts to use it elsewhere in the program result in a compilation error.
The SHARED directive specifies that this method or field are a class method or a class field respectively (static class members). Static methods and static fields are not a part of a particular class instance. Regardless of the number of created class instances, there is only one copy of the static field. Static fields start existing after they are referred to for the first time and stop existing after the application domain is shut down.
NOTE. Values of static fields are unique within different connections to the same repository.
Non-static members can use any static or non-static class members. Static members can use only static class members. The Self identifier can be used to address static members within a class, or it is possible to simply indicate the static member name.
The FINAL directive specifies that this method cannot be redefined in the children of this class.
Only delegates can be used as an event type. Delegates define what kind of signature a method shall have to be the specified event handler. An assignation operation is only available for the events with a method name in its right part. The method signature must match the delegate signature. The assignation operation is used to assign a new event handler.
Class SampleClass: Object
Private Shared Temp: Integer;
Public Shared Sub Test;
Begin
Temp := TestEx(1);
//...
End Sub Test;
Public Shared Function TestEx(Index: Integer): Integer;
Var
i: Integer;
Begin
//...
Return i;
End Function TestEx;
Public Sub CreateSettings(Count: Integer);
Begin
//...
If Count < 1 Then
//Call method via Self
Self.Test;
Else
//Call method without using Self
Temp := TestEx(Count);
End If;
End Sub CreateSettings;
Public Final Property GetValue: Integer
Get
Begin
//...
Temp := Correct(Temp);
//...
Return Temp;
End Get
End Property GetValue;
Private Function Correct(Value: Integer): Integer;
Var
i: Integer;
Begin
//...
Return i;
End Function Correct;
End Class SampleClass;
See also: