Declaring Procedure Set Methods

A Procedure Set method performs a discrete operation, then sets some state, or attribute, of the object. Procedure Set mimics the setting of a property. A Procedure Set method should not take more than one parameter, it was designed for use with properties. The syntax for declaring a Procedure Set Method is:

Procedure Set {method-name} [{type} {param}]


    {statement 1}

    {statement 2}


    {statement n}




You can define zero or more parameters for each Procedure Set method. Each parameter behaves like a local variable that is initialized by the statement that executes the method.  The data types of each parameter can be any of the DataFlex simple types (Integer, Number, Real, etc.) as well as struct types and arrays.

By Reference parameters can also be declared. In this case the parameter's name must be preceded by the keyword "ByRef". When a parameter is passed by reference, the procedure has direct read/write access to the passed variable. For more information to Parameter Passing.


Here is an example of a class definition that declares a Procedure Set method:

Class cCountButton is a Button

    // Constructor:

    Procedure Construct_Object

        Forward Send Construct_Object   // very important!

        Property Integer Private_piClickCount  0



    Procedure Set piClickCount Integer iValue

        Set Private_piClickCount To iValue

        Set Label                To iValue



    Function piClickCount Returns Integer

        Integer iValue

        Get Private_piClickCount To iValue

        Function_Return iValue



    Procedure OnClick

        Integer iCount

        Get piClickCount   To iCount

        Move (iCount + 1)  To iCount

        Set  piClickCount  To iCount



The class declaration in the above example is a new Button class that is designed to record how many times it has been clicked and display that number in the button's label. A Procedure Set method has been defined to take care of setting an internal property that records the number of clicks. This Procedure Set will also perform the task of setting the button's label. A Function has also been designed to retrieve the value of the internal property. Therefore, we have defined a new interface to set and read the number of times that the button has been clicked. The new interface guarantees that each time the piClickCount property is set, the button's label will also be adjusted.

The Button class is designed to execute a method called OnClick each time the button is clicked by the mouse. The OnClick method we have defined reads the piClickCount property to a local variable, increments it, then sets piClickCount to the incremented value. The Get piClickCount statement will execute the piClickCount function method and the Set piClickCount statement executes the piClickCount procedure set method. Thus the declaration of a Procedure Set and a Function method simulate a new class property called piClickCount.

Note that the name of the actual property declared (Private_piClickCount) is different than that of the Function and Procedure Set method pair (piClickCount). If this were not the case, the Function and Procedure Set method pair declared in the same class where the property is declared would not execute.

You may create Function and Procedure Set methods of the same name as a property in a subclass of the class where the property is declared, but not in the same class.