Easy Object Referencing
Object Referencing
Any object name used anywhere within a DataFlex program may now be referenced without the (self) syntax. The object may be referenced just by its name.
In DataFlex 8.2 and higher, an object is referenced as follows:
Get Message of oName to bVar // instead of
(oName(self))
Move (Message(oName)) to bVar // instead of (Message(oName(self)))
Prior to DataFlex 8.2, object names in expressions always required the oName(self) syntax. In DataFlex 8.2, the (self) component is no longer required (though still supported). This builds upon changes made in VDF5 where we allowed simplified object name access outside expressions, as shown in the following examples:
Send Message of oName
Get Message of oName to svar
Move oName to hoVar
We now support this inside expressions as well:
Move (Message(oName)) to svar
Move (oName) to hoVar
This change makes the use of object-referencing names easier and more consistent throughout the language. This change applies to object names used anywhere within an application:
new: Move (Label(oMyObj)) to sVar
was: Move (Label(oMyObj(self))) to sVar
new: Move (value(oMyObj,0)) to sVar
was: Move (value(oMyObj(self),0)) to sVar
new: Set Server to oMyObj // setting property to an object name
was: Set Server to (oMyObj(self))
new: Move (label(oMyObj) + ":" + value(oMyObj,0)) to sVar
was: Move (label(oMyObj(self)) + ":" + value(oMyObj(self),0)) to sVar
new: Send MyMessage of oMyObj oSomeObj // passing object as a parameter
was: Send MyMessage of oMyObj (oSomeObj(self))
new: Move (Value(oMyObj,item_count(oMyObj)-1)) to sLastItem
was: Move (Value(oMyObj(self),item_count(oMyObj(self))-1)) to sLastItem
This only works with actual object names. All other GET expressions (e.g., functions and properties) require the traditional expression syntax. For example, the following syntax will not work (and never has):
// these will not work
Set piMyProperty to (piMyProperty + 1)
Set Value iItem to (Value(item) * 2)
The names piMyProperty and Value are not object names; they are the names of properties and functions. When used in an expression, you must still pass the object handle of the property or function. In the above case, the proper code is:
Set piMyProperty to (piMyProperty(self) + 1)
Set Value iItem to (Value(self, item) * 2)
If an object name has the same name as a variable, the name of the variable will be used before the object name. For example:
// a very bad program
Object oMy is a Form
Procedure Foo
Integer oMy
Move oMy to oMy // will move variable value to itself
Set Server to oMy // will set to the variable and not the object
End_Procedure
End_Object
This is obviously very badly written code. Do not assign variables the same name as objects. Properly written, this program will be:
// a very good program
Object oMy is a Form
Procedure Foo
Integer hoMy
Move oMy to hoMy
Set Server to hoMy
End_Procedure
End_Object
There will never be any conflict between object names and other function names because you are not allowed to assign the same name to an object and a function/property. If you attempt to do this, you will receive a compiler error. If you follow our suggested naming convention of inserting an "o" in front of all object names, it will be very clear when you are using an object and when you are using something else.
Using the new simpler syntax means less complex expressions with fewer parentheses. Your programs should be easier to write and much easier to read. When you use this along with the new neighborhood object addressing methods, your programs will be even easier to write.
All these changes are completely backwards compatible. Existing programs will run as before.