Data Access Worldwide Knowledge Base

Article ID 2095
Article Title INFO: Global Methods
Article URL http://www.dataaccess.com/kbasepublic/KBPrint.asp?ArticleID=2095
KBase Category VDF11
Date Created 03/08/2005
Last Edit Date 03/08/2005


Article Text
There was a change in recommendations made back in 9.0.

A method can be Global and you use the same GLOBAL syntax as ever. Its status has not changed. Of course one should try to make as few global functions and procedures as possible.

Function gFoo Global integer i1 returns string

Move (gFoo(i1)) to sVal

A method can be defined to be on the desktop by using the DESKTOP keyword. This is an OO method and can be accessed by sending directly to the desktop or delegation.

Function DesktopFoo DESKTOP integer i1 returns string

Get DesktopFoo of Desktop i1 to sVal
<or>
Get DesktopFoo i1 to sVal // resolve via delegation

We no longer recommend using the FOR Syntax (e.g. for Desktop, for cDesktop, for cObject) and no longer recommend ambiguous methods on the desktop (e.g. a method outside of all objects that does not contain a DESKTOP or GLOBAL keyword).


From the Class Reference, under cDesktop:


Functions and Procedures defined at the Desktop

We recommend that global functions and procedures be used sparingly. In an object-based system, you should use methods, properties and events.

A desktop method is defined by using the keyword desktop within the message declaration.

Function MyDesktopFoo Desktop Integer i returns String

If the word Desktop immediately follows the method name, then this method becomes a method of the desktop object. The desktop object is the container object for all other objects in VDF. Desktop methods can be resolved either by sending the method directly to the Desktop or by delegation (assuming the objects within the desktop object all support delegation and the method is not understood by some other object).


// the method is resolved by sending directly to the desktop
get MyDesktopFoo of Desktop iVal to sString

// the method will be solved by delegating to the desktop
get MyDesktopFoo iVal to sString

Like the Global keyword, the Desktop keyword can be used anywhere to mark a method as a desktop method. Desktop methods are object-based methods. Therefore, you can use this name for a desktop method and use the same name for any other object or class you wish.

We also recommend that desktop methods be used sparingly. If your application contains many desktop methods or many global functions/procedures, you may wish to review your program structure. You may be creating code that is not properly encapsulated.



Compatibility Notes

The Desktop syntax was added to revision 8.3. Also note that this syntax is different than using the old "for Desktop", a syntax which is highly discouraged.

As of revision 8.3, we suggest that all methods that are coded at the desktop level (i.e. methods not contained within any other class or object) be explicitly marked as being GLOBAL or DESKTOP. All other syntaxes are considered either obsolete or not recommended. In particular, previous versions of Visual DataFlex allowed methods placed on the desktop to contain no special marking. We refer to this as an "ambiguous" desktop method:


// if this were on the desktop, it would be considered Ambiguous
Function MyDesktopFoo Integer i returns String

We now discourage the use of ambiguous desktop methods. In 8.3, all old syntaxes will be supported including ambiguous desktop methods. They will continue to work exactly as they did in all prior versions of Visual DataFlex. However, using ambiguous desktop methods is now strongly discouraged. In future revisions Visual DataFlex , ambiguous desktop methods will generate error messages. Therefore, we advise that you start changing your programs now. Also note that an ambigious method is neither global or desktop - it actually modifies the cObject class, an action that is strongly discouraged.






Contributed By:
John Tuohy
Company: Data Access Worldwide
Web Site: http://www.dataaccess.com


Email this Article
Email this Article to a Colleague
Send Feedback on this Article to Data Access Worldwide
Copyright ©2010 Data Access Corporation. All rights reserved.

The information provided in the Data Access Technical Knowledge Base is provided "as is" without warranty of any kind. Data Access Corporation disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. In no event shall Data Access Corporation or its suppliers be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages, even if Data Access Corporation or its suppliers have been advised of the possibility of such damages. Some states do not allow the exclusion or limitation of liability for consequential or incidental damages so the foregoing limitation may not apply.