Skip to content

Reading Properties using Expressions

DataFlex supports two distinct ways to read the properties of an object. The first syntax is to use a Get statement, and the second syntax is to read the property within an expression.

Syntax for Reading Properties

The syntax of the Get statement for reading a property is:

Get {property-name} [of {object-id}] To {variable-id}

Where:

  • {property-name} is the name of the property that is being read.
  • {object-id} is a handle to the object whose property is being read.
  • {variable-id} is the name of a variable that will receive the property's value.

This syntax is fully discussed in the section on Reading Property Values. The syntax for reading a property using an expression is:

({property-name}({object-id}))

Notice that the {object-id} is a compulsory part of the expression syntax for reading a property. If the object property is in the same object as the one sending the message, the keyword Self must be used as the object ID.

Example of Expression Syntax

Below is an example of using expression syntax to read a property value, followed by the equivalent Get statements:

Move (Label(Self)) To sLabel   // self is required
Get Label To sLabel            // self is implied
Get Label of self To sLabel    // self is explicit (but was not required)

If the object property is in a different object than the object sending the message, the object must be named. Below are some examples of using expression syntax to read property values from another object, followed by the equivalent Get statement:

Move (Label(oButton)) To sLabel
Get Label of oButton To sLabel

Sending a Message to Yourself

Often, an object will send a message to itself. This means that the object that is sending the message is also the object receiving the message. When this occurs, the predefined keyword Self can be used to identify the object ID. In the following example, all messages within an object based on this class are sent to itself, so Self is used to identify the object ID of each message.

Class cMyButton is a Button
    Procedure Construct_Object
        Forward Send Construct_Object
        Property Integer piClickCount 0
    End_Procedure

    Procedure DoAction
        Integer iCount
        Get piClickCount of Self to iCount
        Move (iCount + 1) to iCount
        Set piClickCount of Self to iCount
    End_Procedure

    Procedure OnClick
        Send DoAction of Self
    End_Procedure
End_Class

Because this type of message sending occurs so often, the {of self} syntax may be omitted. When an object ID is not identified, the current object (self) is assumed. Therefore, the above example could be more easily written as:

Class cMyButton is a Button
    Procedure Construct_Object
        Forward Send Construct_Object
        Property Integer piClickCount 0
    End_Procedure

    Procedure DoAction
        Integer iCount
        Get piClickCount to iCount
        Move (iCount + 1) to iCount
        Set piClickCount to iCount
    End_Procedure

    Procedure OnClick
        Send DoAction
    End_Procedure
End_Class

In the above example, the Label property of an object called oButton is read into a variable called sLabel.

Alternatively, the object handle can be moved to a variable and used in an expression as follows:

Handle hoButton
Move oButton to hoButton
Move (Label(hoButton)) to sLabel

In the following example, the Enabled_State property of an object called oButton is evaluated in an If statement:

If (Enabled_State(oButton)) Showln "This button is enabled"
Get Enabled_State of oButton To bEnabled
If (bEnabled) Showln "This button is enabled"

The following example shows how multiple properties may be evaluated within a single expression. Several different coding styles are demonstrated that all accomplish the same goal.

Style A

If (Changed_State(oCustomer_DD) AND;
    Allow_Update_State(oCustomer_DD) AND;
    (Find_Mode(oCustomer_DD) = MODE_SAVING));
    Send DoUpdateStatus

Style B

Handle hoCustomer_DD
Move oCustomer_DD To hoCustomer_DD
If (Changed_State(hoCustomer_DD) AND;
    Allow_Update_State(hoCustomer_DD) AND;
    (Find_Mode(hoCustomer_DD) = MODE_SAVING));
    Send DoUpdateStatus

Style C

Handle hoCustomer_DD
Integer bChanged bAllowUpdate iMode
Move oCustomer_DD to hoCustomer_DD
Get Changed_State of hoCustomer_DD to bChanged
Get Allow_Update_State of hoCustomer_DD to bAllowUpdate
Get Find_Mode of hoCustomer_DD to iMode
If (bChanged AND bAllowUpdate AND (iMode = MODE_SAVING));
    Send DoUpdateStatus
  • Style A uses the expression syntax to evaluate each property and is the most concise. It would be less efficient to execute than the other two styles.

  • Style B also uses expression syntax, but the object ID has been evaluated first and is passed to the expression in a handle variable. This style is slightly more verbose but the code is more efficient.

  • Style C is the most verbose. It uses Get statements to retrieve the property values so that they are not evaluated in the If statement. The result is a much simpler If statement. The code would also be more efficient if the properties were used more than once because the values have already been retrieved into variables.