Tips_todo   >   Notation   >   Current Notation

Current Notation

This section covers current objects notation ($ctask, $clib, $cinst, $c...) and provides demos for each. Current notation is very helpful in shortening notation strings and making your code flexible and generic.

Current notation is a reference to the item. $clib is a reference to the library. A reference to an item lets you find out or assign properties of that item.

FROM THE OMNIS HELP NOTES

Under $root, Omnis contains a number of global state variables that tell you about how Omnis is currently executing, or what objects, instances, and methods are currently being used. These objects provide a shortcut to the current object or instance that is currently executing. Mostly their names begin with "$c".

You can use the current objects in place of the full notation for a specific object to make the object and its code reusable and portable between libraries. For example, you can use $cinst in a method within a window instance to refer to itself, rather than referring to it by name.

$cinst
rather than
$root.$iwindows.WindowInstanceName

You can refer to the current library using $clib. For example, to make the current library private using:
Do $clib.$isprivate.$assign(kTrue)

is more generic than:
Do $libs.MyLibrary.$isprivate.$assign(kTrue)

Current Class - $cclass

$cclass is the class which the method is located in.

Click the run demo button to see the $cclass of this method.

Current Data File - $cdata

The current open data file. Useful for OmnisDML only.

Current Field - $cfield

The field where the current method is executing.

For some window objects I add a $construct method so that the field will set some of its own properties when the window is being instantiated. $cfield works great for those situations.

Do $cfield.$edgefloat.$assign(kEFposnClient)

Current Instance - $cinst

The current instance; usually the instance containing the currently executing method.

Almost everything you run in Omnis Studio is an instace of the actual class, not the class. Code classes, schema classes, and search classes are exceptions.

Think of an instance as a photocopy of the original. You can have as many photocopies as you want. Each photocopy has a $name property which is automatically assigned, or can be assigned using notation.

Click the run demo button to see the $cinst of this object class.

Current Library - $clib

$clib is the library the current class is located in.

Click the run demo button to see the $clib of this object class.

Current Method - $cmethod

The currently executing method.

Click the run demo button to see the $cmethod of this method.

Current Object - $cobj

The current object that received a $event message.

$cobj is great for event handling methods. You could be 3 methods away from the pushbutton that was clicked and $cobj still gives you a direct reference to the pushbutton.

Click the run demo button to test $cobj of the run demo pushbutton.

Current Recipient - $crecipient

The current recipient of an event; if a custom method is being processed, $crecipient is the recipient of that method.

Methods inside of any "container" field can refer to their "container" using $crecipient

Calculate ContainerName as $crecipient().$name

Thanks to Wietse Jacobs for this tip.

The "container" that Wietse refers to is the "object" that the method belongs to. At first I thought he meant "container fields" like Page Pane, Group Box, Tab Pane.

After doing some testing (Run Demo) I realized that the $crecipient "container" is the object or class that the "method" is "contained" in.

If the method belongs to a window object, then $crecipient will be the object. If the method is a class method of a window, then $crecipient is the window class.

An interesting discovery while making the demo is that using:

Do method $_ClassMethodName does NOT change the $crecipient. Whereas:

Do method $cinst.$_ClassMethodName

or Do $cinst.$_ClassMethodName
DOES change the $crecipient.

I recall a discussion that "Do method $_ClassMethodName" does NOT add to the method stack (affecting max stacked methods), whereas, "Do method $cinst.$_ClassMethodName" and "Do $cinst.$_ClassMethodName" do add to the method stack.
The fact that "Do method" does not change the $crecipient might be related to the above discovery.

You can test all of the above in the demo.

Current Target - $ctarget

A reference to the target field, that is, the field which currently has the focus (shows the caret
and is sent keyboard events)

The notational equivalent of "Queue set current field" is:
Do $ctarget.$assign(rFieldObject)

Using "Do $ctarget.$assign" is more reliable than Queue set current field.

You can not use "Queue set current field" for subwindow fields from outside the subwindow's window instance, whereas you can use $ctarget.

GOTCAH: The window/pane must already be visible (in front) before you issue $ctarget. You can not use $ctarget.$assign during the $construct of a window instance. If you are changing tabs in a tab pane, make sure the "tab clicked event" has been processed before you attempt to use $ctarget. (This one had me stumped for a while!)

Current Task - $ctask

In Omnis Studio when you open a window you open an instance of the window. Just about everything in Omnis runs in an instance of the actual class. The instances all run with a task instance.

Many applications just run under one task instance, the Startup_Task instance.

The Startup_Task instance name defaults to the same name as the library name which the Startup_Task task class is located in.

Click the run demo button to see the $ctask of this object class instance.

Current Window - $cwind

The current window instance.

For subwindow window instances $cwind is the parent window. Don't use $cwind if $cinst will work for you. $cwind changes depending on which window is on tip, this could cause your code to break. Always think for minute before you use $cwind.

For window menus and toolbar, you would use $cwind to send a message from the menu or toolbar to the window. Each menu and toolbar has its own instance so from inside those intances $cinst would point to them, and $cwind would point to the window which "owns" the window menu orwindow toolbar. However, a "better" ways it to use the "observer" design pattern. See menus on-the-fly for more details and a demo.

TIP: If you need to find out whether or not a window is a subwindow, compare $cinst to $cwind.

If $cinst<>$cwind
; The $cinst is a subwindow.
End If

Click the run demo button to test $cwind.

Top Window - $topwind

The topmost open window instance.

Click the run demo button to test $topwind.