See Also: DataFlex Classes, End_Class, End_Object, Forward, Function, Object, Procedure, Property


To create a new DataFlex object class. A class defines a DataFlex object's behavior.


Class {sub-class} Is A {super-class}




What It Does

The class command creates a new class {sub-class} with all the properties, function and procedure methods of its parent class, {super-class}. These inherited characteristics are then modified in the succeeding commands (until the End_Class command) to produce the new class.

{Sub-class} may be any unique class name. Objects of the new class are created using the Object command. The {sub-class} name should be descriptive of its use in the program.

{super-class} is the class from which the new class inherits. The new class begins with all of the procedures, functions, properties and key definitions of the parent class. The job of the Class command is to add, change, or cancel the abilities of {super-class} to achieve the goals of the new {sub-class}.

{super-class} must be defined in the program before it is used as a parameter to the Class command.

Class definitions are commonly placed in package files, so that the code can be reused; however, this is not a requirement. Definitions of classes of broad applicability are best placed in package files so that many programs may use them.

Within the class definition, there are declarations of procedures and functions. These methods define an object's behavior. An object can also store its state in properties. Property declarations are made in the Construct_Object message, the message sent by the system when an object is created. Class definitions are terminated by the End_Class command.


The following example demonstrates sub-classing and inheritance:

Class cBasicButton Is A Button

    Procedure Proc_1

        Showln "Overridden: This line never prints."



    Procedure Proc_2

        Showln "Forwarded: Inside Proc 2 of cSuperClass"



    Procedure Proc_3

        Showln "Inside Proc 3 of cSuperClass"




Class cMyButton Is A cBasicButton

    Procedure Proc_1  // Override Proc 1

        Showln "Override. Inside Proc 1 of cSubClass"



    Procedure Proc_2  // Forwarding example.

        Showln "Before forwarding. Inside Proc 2 of cSubClass"

        Forward Send Proc_2

        Showln "After forwarding. Inside Proc 2 of cSubClass"



    Procedure Proc_4  // Procedure only declared in cSubClass.

        Showln "Inside Proc 4 of cSubClass"




Object oTest Is A cMyButton

    Procedure OnClick

        Showln "This program demonstrates inheritance"

        Send Proc_1

        Send Proc_2

        Send Proc_3

        Send Proc_4



The following example demonstrates declaring a new class with new properties:

Class  cOK_Button  is a Button

    // Constructor:


    Procedure Construct_Object

        Forward Send Construct_Object   // very important!


        Property Integer piClickCount  0

        Property String  psBusyLabel   "-Busy-"



This example declares a class, cOK_Button, with two new properties, piClickCount and psBusyLabel. Note that the properties are declared inside the class constructor method, Construct_Object. An important part of the Construct_Object method is the "Forward Send Construct_Object" statement. This is the line that ensures that all of the definitions in the superclass's constructor are inherited by the new class.