Skip to content

Class: cDesktop

Properties | Events | Methods | Index of Classes

Used to create the desktop object which contains all other objects within an application

Hierarchy

cObject > cUIObject > DfBaseObject > DfBaseWindow > DfBaseUIWindow > DfBaseContainer > DfBaseDialog > DfBasePanel > cDesktop

Show full hierarchy and direct subclasses

Library: Common Class Library

Description

A single desktop object is automatically created in every program. It is based on the cDesktop class. Objects that are not surrounded by other objects in a program are actually still child objects - they are children of the Desktop, and are also known as global objects.

The Desktop object is created for for you. You cannot create additional desktop objects and you cannot sub-class the cDesktop class. You can create additional methods and properties for the desktop object - this is described below.

The Desktop and Delegation

Messages received by an object that does not understand them are typically delegated to the receiving object's parent object. If the message is not understood by the parent object, the parent delegates the message until some ancestor object understands the message. If none does, it is ultimately delegated to the ultimate object, the Desktop. If the Desktop does not understand the message, an error is generated.

Sending Messages Directly to the Desktop Object

Messages can also be sent explicitly to the desktop by sending the message to the object named desktop

Get Focus of Desktop to iVar

Creating objects on the Desktop

An object can be added to the deskop using one of two methods. If you create an object using the Object and End_Object command that is not placed inside of any object, this object is a child of the desktop. You can also create an object for the desktop by sending the create messages directly to the desktop object.

Get Create (RefClass(cObject)) of Desktop to hoObject

Desktop and Global Functions/Procedures

DataFlex allows you to create methods (functions and procedures) that reside on the desktop. It also allows you to create global function and procedures. While these may seem to do the same thing, they are quite different.

Global Functions and Procedures

A global function or procedure is global to your entire application and exists outside of the object-oriented model. Because it is global they are not messages and they are not sent to an object. They are part of the global structure. Global procedures and functions are not as flexible as object oriented methods.

A function or procedure is defined as global by using the keyword global within the declartion.

Function MyGlobalFoo Global Integer i Returns String

If a function or procedure is marked as being Global it is actually not a method at all. It is a function or procedure, which is accessed outside of any object considerations. A global function/procedure can be defined anywhere in an application and it can be defined one time only. Once a name is assigned to a global function or procedure that name can not be used for any other class and object methods. In other words object methods and global functions/procedures can not have the same name and will result in a compiler error.

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 DataFlex. 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.

Defining a method For Desktop is effectively the same as saying For cObject, so it adds the method to the cObject class. This means that any class derived from the cObject class will implicitly understand the method, and thus does not delegate it up to the Desktop object, because any object derived from cObject understands the method itself.

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 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 DataFlex. However, using ambiguous desktop methods is now strongly discouraged. In future revisions 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.