Skip to content

Set

Online Version

See Also: Get, Property, WebGet, WebSet

Purpose

To set the value of an object property.

Note: For web applications, you will most likely use WebGet and WebSet instead of Get and Set. Please see those commands for more information.

Syntax

set
    property [
        of object
    ] to value

set
    property [
        of object
    ] [item_number] to value

What It Does

The set command is designed to set values of the properties of objects. Objects of every class are composed of storage locations for information pertaining to the operation of the object. The set command places (value) into one of these storage locations (property).

For most of the object properties in classes predefined in DataFlex, a pair of messages, one get and the other set, is provided. Consult the property list in each class to determine which commands are provided for the property in question, and the exact name of the message for each.

Procedure IncrementCount
    Integer iCount
    Get piHitCount to iCount
    Increment iCount
    Set piHitCount to iCount
End_Procedure

The object that receives the message may be either explicitly specified (to object) or omitted, in which case the object identified is the current-object (self, i.e., the object that sends the message also receives the message).

The following two samples are the same. In both cases, the property from object Customer_DD is being queried from some other object.

Set Changed_State of Customer_DD to True
Handle hCustomer_DD
Move Customer_DD to hCustomer_DD
Set Changed_State of hCustomer_DD to True

The following two samples are also the same. In both cases, the property is being queried from the object that is sending the message.

Set Changed_State to True
Set Changed_State of Self to True // "of Self" is not required

Some properties are associated with object items, rather than the object overall. For those properties, an item index number should be specified (item_number). Some item-based properties allow you to omit the item index in which case the value 0 or the value of current_item of the object is used.

Struct Properties

Special consideration needs to be given for accessing data that is stored in class properties that are of struct type. The Get and Set commands that are used for accessing a property's data can only be used to get and set the entire struct. This works just like a struct variable assignment.

To read or write individual members of a struct property, it is necessary to get the property to a local struct variable of the same type. You would then manipulate the data of this local struct and write back the changes by setting the struct property once again.

Example

struct tNameAndAddress
    string sName
    string sAddress
end_struct

Class cMyButton is a Button
    Procedure Construct_Object
        Forward Send Construct_Object
        // Declare a struct property
        Property tNameAndAddress pContact
    End_Procedure

    Procedure StoreName String sName
        tNameAndAddress contact // create a local struct variable
        // get the struct property to the variable.
        Get pContact to contact
        // show the current name.
        Send Info_Box ("The current name is: " + contact.sName)
        // change the name.
        Move sName to contact.sName
        // Save the change back to the struct property.
        Set pContact to contact
    End_Procedure
End_Class

Array Properties

Special consideration needs to be given for accessing data that is stored in array properties. The Get and Set commands that are used for accessing a property's data can only be used to get and set the entire array. This works just like an array variable assignment.

To read or write individual array property elements, it is necessary to get the property to a local array variable of the same type. You would then manipulate the data of this local array and write back the changes by setting the array property once again.

Example

Class cMyButton is a Button
    Procedure Construct_Object
        Forward Send Construct_Object
        // Declare an array property
        Property string[] psNames
    End_Procedure

    Procedure StoreName String sNewName
        string[] sNames // create a local array variable
        integer iElementCount
        // get the array property to the variable.
        Get psNames to sNames
        // Add the new name.
        Move (SizeOfArray(sNames)) to iElementCount
        Move sNewName to sNames[iElementCount]
        // Save the change back to the array property.
        Set psNames to sNames
    End_Procedure
End_Class

Item-Based Properties

The compiler must explicitly recognize that a message requires an index parameter. Special compiler commands are created to identify these messages. The indexed messages identified as current-item based, which means that current_item is used if the index parameter is omitted, are:

  • Value
  • Aux_Value
  • Shadow_State
  • Select_State
  • Checkbox_Item_State
  • Autoclear_State
  • Center_State
  • Entry_State
  • Item_Changed_State
  • Item_Entry_Msg
  • Item_Exit_Msg
  • Item_Validate_Msg
  • Data_File
  • Data_Field
  • Data_Window
  • Item_Options
  • Item_Option
  • Prompt_Object
  • Zoom_Object

The indexed messages identified as form based, which means that zero is used if the index parameter is omitted, are:

  • Form_Width
  • Form_Color
  • Form_Datatype
  • Form_Options
  • Form_Font
  • Form_Row
  • Form_Column
  • Form_Typeface
  • Form_Fontheight
  • Form_Fontweight
  • Form_Fontitalics
  • Form_Fontunderline
  • Button_Aspect
  • Form_Height
  • Form_Guiwidth
  • Form_Guheight
  • Form_Guirow
  • Form_Guicolumn
  • Form_Margin
  • Form_Option
  • Form_Style
  • Form_Extended_Style
  • Form_Border
  • Password_State
  • Form_Mask
  • Form_Button
  • Form_Button_Value
  • Form_Window_Handle

The difference between current-item based and form based messages are historical. Since we only recommend that you omit the index parameter on single item objects, the current-item should always be zero. This means that both types of messages should be treated the same.

We advise that you always omit the item index parameters for objects that are single item objects (in which case current_item should be zero anyway). Examples of single item objects are dbForms, Forms, and ComboForms. For example, when in a dbForm the Value property should be accessed as follows:

Set Value of oMyDbForm to "form test value"

We advise that you always include the item index parameter in multi-item objects. Examples of multi-item objects are Arrays, Grids, dbGrids, and dbLists. For example, when in an array the Value property should be accessed as follows:

For iCount from 1 to 10
    Set Value iCount to "Array test value"
Loop

Every property has a known data type. If value is a variable of other than the type specified in the property, its value will be converted automatically to the required type.

Notes

  • In older programs, you will see the keyword item before the index value (e.g., set Value item0 to "x"). The item keyword is optional. Its usage is no longer recommended.