Tips   >   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.
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.
Within the class instance you can use $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)$cclass
is the class which the method is located in.
Click the $cclass of this method.
button to see theIf you are dealing with superclass methods, $cclass in a superclass method will evaluate to the class of the superclass, not the class of the subclass. To evaluate to the class of the subclass use $cinst().$class.
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 or if I want to set an ivar to point to the object. $cfield works great for those situations.
Do $cfield.$edgefloat.$assign(kEFposnClient)
Set reference irButton to $cfield
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 button to see the $cinst of this object class.$clib
is the library the current class is located in.
Click the button to see the $clib of this object class.The currently executing method.
Click the button to see the $cmethod of this method.The current object that received a $event message.
$cobj should be used whereever possible in your 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 button to test $cobj of the run demo pushbutton.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 can refer to their container using $crecipient
Calculate FieldName as $crecipient().$name
The $crecipient container is the object or class that the executing method is contained in.
If the method belongs to a window field, then $crecipient will be the field. 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 by clicking the button.A reference to the target field, that is, the field which currently has the focus (shows the caret and is sent keyboard events)
Set reference rField as $ctarget
You can $assign the $carget to set the focus on a visible field.
Do $ctarget.$assign(rField)
This is the notational equivalent of Queue set current field.
You can not use Queue set current field for subwindow fields from a method outside the window's window instance, whereas you can use $ctarget.
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 evTabSelected event has been processed before you attempt to use $ctarget. The field you are attempting to set the $ctarget must be enabled at the time you attempt to $assign the $ctarget.
If there are other events in event queue which will affect the $ctarget, you can assign the $ctarget in your code, but it will be changed when the other events are processed. In those cases Queue set current field is the only reliable solution... but you must execute Queue set current field from a method within the window class of the field. I have a public method in my superclass window called $setCurrField which I use for setting the current field.
When you open a library, Omnis Studio sends looks for a task named Startup_Task. If found, Omnis Studio automatically opens and instance of the Startup_Task and sends it a $construct message.
The Startup_Task instance name defaults to the same name as the library name which the Startup_Task task class is located in.
Any class instances (menu instance, toolbar instances, window instances) which you open from the $construct by are by default contained within the Startup_Task instance.
Any additional class instances opened by those class instances (e.g. A menu line is selected by the user to open a window instance or run a report instance) are also by default contained within the originating task instance. (even if those classes are from different libraries)
Each library can have it's own task and you can open additional tasks. Many applications just run under one task instance, the Startup_Task instance.
$ctask is the current task
Click the button to see the $ctask of this object class instance.The current window instance.
For subwindow window instances $cwind is the outermost parent window instance. Don't use $cwind if $cinst will work for you. $cwind changes depending on which window is the outermost parent, this could change cause your code to break. Always think for minute before you use $cwind.
For window menus and window toolbars, 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 the menu or toolbar instance, 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.
If you need to find out whether or not a window is a subwindow, compare $cinst to $cwind.
; Test for a subwindow instance.
If $cwind=$cinst
; This window instance is the outermost window instance.
Else
; This window instance is a subwindow.
End If
The topmost open window instance.
Click the button to test $topwind.