CLASSMODULE


10.6

 

The CLASSMODULE compiler directive is required when compiling a PL/B load module as a class to be used for a PL/B code object (PLBOBJECT). This directive must be the first instruction in the source for a load module. Otherwise, an appropriate compiler error is generated. This instruction uses the following format:

 

 

CLASSMODULE

Flags Affected: NONE

Note the following:

  1. The CLASSMODULE statement must be the first instruction in the load module source module.

  2. The CLASSMODULE invokes specialize compiler behaviors when compiling a load module so it can be loaded and accessed using a PLBOBJECT code object. These behaviors include the following:

  3.  

    Plbcmp CLASSMODULE behaviors

     

    1) No common data allowed.

    2) ROUTINE, LROUTINE, and PROCEDURE instructions are not allowed.

    3) CHAIN is not allowed.

    4) TRAP is not allowed.

    5) A CLASSMODULE instruction creates a SHUTDOWN as the first instruction in a load module. Therefore, the CLASSMODULE '.plc' program can not be executed as a standalone program.

    6) The compiler flags the '.plc' of the load module so the PL/B runtimes can invoke specialized behaviors.

    7) If PL/B instructions use a PLBOBJECT as a program is compiled, the compiler accesses the current CLASSMODULE FUNCTION labels to verify properties and methods being accessed. This feature can only be used if the CLASSMODULE '.plc' exists when a PLBOJBECT is being compiled into a PL/B program. Otherwise, the compiler gives appropriate warning messages.

     

  4. When a CLASSMODULE load module is being loaded and used for a PLBOBJECT the following behaviors are expected:

  5.  

    A. All data declared in a CLASSMODULE load module is private.

    B. The PL/B runtime ONLY allows a CLASSMODULE load module to be accessed by a PL/B instruction that is using a PLBOBJECT code object.

    C. The PLBOBJECT can be used in the following instructions when accessing/using a CLASSMODULE.

     

    CREATE OBJOBJECT

    GETPROP OBJOBJECT, property=var...

    SETPROP OBJOBJECT, property=var...

    DESTROY OBJOBJECT

    EVENTREG OBJOBJECT ... ( Windows Runtimes only! )

    EVENTSEND *OBJOBJECT ... ( Windows Runtimes only! )

    OBJOBJECT.Methods ...

     

    D. There is a U70 error which can occur when a CLASSMODULE is being accessed/used.

    E. A CLASSMODULE load module must include two special FUNCTIONS named as follows. If these functions do not exist when a PLBOBJECT is used in a CREATE or DESTROY instruction, an appropriate object error occurs.

     

    ClassCreate FUNCTION

                  ENTRY

    .

    . User create logic if needed.

    .

                 FUNCTIONEND

     

    ClassDestroy FUNCTION

                 ENTRY

    .

    . User destroy/cleanup logic if needed.

    .

                FUNCTIONEND

     

    F. The CLASSMODULE PL/B source includes properties and method FUNCTIONs which are accessed using GETPROP, SETPROP, and methods. See the sample CLASSMODULE skeleton found in the 'class_skeleton.pls' sample program.
         The PL/B Label syntax identifies a FUNCTION to be used for a GETPROP, SETPROP or a method as follows:

     

    'Get_PROP' identifies a FUNCTION to be accessed using a GETPROP instruction where 'PROP' is the property name:

     

    GETPROP PLBOBJECT, *PROP={var}

     

    'Set_PROP' identifies a FUNCTION to be accessed using a SETPROP instruction where 'PROP' is the property name:

     

    SETPROP PLBOBJECT, *PROP={var}"

     

    A simple PL/B Label for a FUNCTION identifies a FUNCTION to be accessed using PL/B method syntax as follows:

     

    GETPROP PLBOBJECT, *PROP={var}"

Examples:

 

// User defined GETPROP FUNCTIONs in CLASSMODULE:

 

*

.

Get_Prop1 FUNCTION //GETPROP 'Prop1' property

             ENTRY

.

. User 'Prop1' logic

.

             FUNCTIONEND USING Prop1Value

*

.

Get_Prop2 FUNCTION //GETPROP 'Prop2' property

            ENTRY

.

. User 'Prop2' logic.

.

           RETURN USING Prop2String

.

           FUNCTIONEND

 

// User defined SETPROP FUNCTIONs in CLASSMODULE

 

*

.

Set_Prop1 FUNCTION //SETPROP 'Prop1' property

Prop1Val FORM 5

             ENTRY

.

. User 'Prop1' logic with input 'Prop1Val' value

 

             FUNCTIONEND

*

.

Set_Prop2 FUNCTION //GETPROP 'Prop2' property

 Prop2Str DIM 10

             ENTRY

.

. User 'Prop2' logic with input 'Prop2Str' string

.

.

             FUNCTIONEND

 

// User defined FUNCTION Labels in CLASSMODULE accessed using PL/B method syntax

 

*

 .

DoReset FUNCTION //Class module 'DoReset' method

dData DIM 100 // Parameter 1

nReset FORM 5 // Parameter 2

             ENTRY

.

. User logic executed for class module DoReset' method

.

             RETURN USING S$CMDLIN

.

             FUNCTIONEND

 

 

See Also: Compiler Directives

 



PL/B Language Reference BYTEX CMPVER