You are on page 1of 2

Class

Language Reference - Commands

See Also Purpose To create a new Visual DataFlex object class. A class defines a Visual DataFlex objects behavior. Syntax
Class {sub-class} Is A {super-class} : End_Class

Where {sub-class} is the name of the new class to create; and {super-class} is the name of the class that the new class is based upon. 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 objects 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. Example The following example demonstrates sub-classing and inheritance:
Class cBasicButton Is A Button Procedure Proc_1 Showln "Overridden: This line never prints." End_Procedure Procedure Proc_2 Showln "Forwarded: Inside Proc 2 of cSuperClass" End_Procedure Procedure Proc_3 Showln "Inside Proc 3 of cSuperClass" End_Procedure End_Class Class cMyButton Is A cBasicButton Procedure Proc_1 // Override Proc 1 Showln "Override. Inside Proc 1 of cSubClass" End_Procedure 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" End_Procedure Procedure Proc_4 // Procedure only declared in cSubClass. Showln "Inside Proc 4 of cSubClass" End_Procedure End_Class Object oTest Is A cMyButton Procedure OnClick Showln "This program demonstrates inheritance" Send Proc_1 Send Proc_2 Send Proc_3 Send Proc_4 End_Procedure End_Object

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 Property Integer piClickCount Property String psBusyLabel End_Procedure End_Class // very important! 0 "-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. Notes New properties must be declared in the class constructor method Construct_Object. Refer to the Visual DataFlex Language Guide for more information on declaring properties. Important! Class declarations may not be nested.

You might also like