Tips_todo   >   Notation   >   Notation References
A reference is a variable of item reference type which is pointing to something in Omnis. A reference could be pointing to a window instance, window class, window object, object method, list variable...
If you are using notation, you will either write very long notation strings or use references and write much shorter notation strings. You can use references to make your code more stable and efficient.
REFERENCES EXPLAINED
I still get confused by references. When to include $ref, when not to, and a few other issues. The following was taken from a list server posting by Tim Stewart. It should help your understanding.
Tim wrote a quick overview of the various references. The posting is listed in the sample code below.There is a confirmed bug with trying to store objects or object instance references in a datalist. (<=v3.3)
The object references appears to work if you test them immediately but then as soon as you change the current line in the list and then come back to it, the object/reference is lost!
Myself and others have burned many hours figuring out this problem and attempting to work around this bug.
This problem hosed my "Observer Design Pattern" where I was trying to store references to object instances in the registered observers list. No matter how hard I tried, I couldn't send messages back to the object instances.
The best workaround that I've seen is Tim Stewart's. He discovered that you can use a row variable and dynamically add a column to the row variable for each object reference you wish to store.
But be warned, apparently if your are using this technique to store a smart datalists, the smartlist is lost.
Tech Support has confirmed the objects in datalist bug. It will be fixed in version 4.0 with the introduction of a new "Object Reference" variable.
Apparently there is another object instance bug where Studio sometimes generates a new instance of an object when send a message to the obejct. I haven't figured out exactly how to replicate this bug.You have a valid reference, now you want to find out what library it is in, what class it is in, etc. (Anything up the $fullname notation string of the item.
To find this information, you add the name of the parent after the reference, then (), then $name of any valid attribute.
Example:
Do $clib.$windows.wContextMenu.$objs.$findname("Field1") Returns rWinWindow objects inside container objects can be referenced notationally directly as window objects. You can leave the 'containers' out of the notation string, and the reference will still be valid. This also applies to subwindow window instance fields. The subwindow's fields become part of the parent window
All of the following references are valid and will work
Set reference rField to $cinst.$objs.SCROLLBOX.$objs.NESTEDSCROLLBOX.$objs.ENTRYFIELD
Do rField.$forecolor.$assign(kRed)
Set reference rField to $cinst.$objs.SCROLLBOX.$objs.ENTRYFIELD
Do rField.$forecolor.$assign(kGreen)
If you are going to use notation to manipulate the properties of any window object, an easy way to get a reference to that object is:
1. Add an item reference instance variable by the name of the field to the window class. (irFieldName)
2. Add a $construct method to the object, if one does not exist already.
3. As the first, and usually only, command in that $construct. "Set reference irFieldName to $cfield"
This will set the ivar reference to the correct field in a manner that is impervious to renaming of the object or even copying and pasting the object into another window.
Example: I often use a Tab bar to control the page of a paged pane that is displayed.
The $construct of the paged pane contains:
Set reference irMainPagedPane to $cfield
The $construct of the tab bar contains:
Set reference irMainTabBar to $cfield
Then the $event method of the tab bar contains:
On evClick
Do irMainPagedPane.$currentpage.$assign(irMainTabBar.$::currenttab)
Neat, huh? I wish that I could claim credit for this tip.
However, it comes from _my_ instructor, Brian O'Sullivan. It was a Studio Tip in late 1998, I think. Craig Lewis
Thanks Craig Lewis for this tip.
NOTE: I use this technique extensively! It works great! Look at all the "ir..." variables in wTips_Browser!There are several ways which you can get or set a reference to something.
1. Set reference - this is the standard Omnis Studio Omnis command for setting a reference.
2. Return a reference from a notational string which will do so.
Thanks to Mark Phillips I rarely use the "Set reference" Omnis command anymore.
Mark taught me about $findname() Return Ref and then testing for null. I've been using it ever since.
Once advantage of using $findname is that it doesn't get messed up by "$" characters in a public method name.
The following "Set reference" will fail.
Set refererence $cclass.$methods.$construct to rMethod
This is maybe an obscure situation but having solved the problem once I thought I may has well add it to StudioTips in case another developer had a similar problem.
Let's say you have an Object A, and create an instance of it. The instance could be in a task instance, or a window instance, or even another object instance. Object A's instance has some values in it. For this discussion we'll assume you want to share the Object A's single instance between 2 different windows. These windows might even be part of separate task instances.
Window A opens an instance of Object A. Window A now wants Window B to share that instance of Object A. You don't want to create additional instances of Object A, you want to share the single instance of Object A.
The trick is to set up an item reference variable in Window B and pass a reference of Object A from Window A to Window B. You must include ".$ref" appended to the end of the Object A instance when passing it to Window B.
Click the Run Demo button to try this out.There is a confirmed bug in Omnis Studio 3x that won't be fixed until version 4.0
I lost more than a few hours tracking it down and eventually reporting it to Tech Support. Hopefully, this note can will save some tips users the same grief.
If you have an item reference instance variable in a superclass this bug can affect you.
Attempting to set or use the superclass item reference instance variable with the prefix "$cinst." will not work.
In my particular case I was using the superclass item reference variable "irMainList" to point to a data list in another object.
This line of code resulted in NULL. It did not work.
Calculate #S3 as $cinst.irMainList.[iFKColName]
This line of code did work.
Calculate #S1 as irMainList.[iFKColName]
Tech support has confirmed the bug, but said it would not be fixed till version 4.0. ST/NT/442
I use the "$cinst." prefix to avoid accidentally overriding superclass instance variables when I copy and paste the superclass code to a subclass method. This nastyn "feature" is supposed to be fixed in version 4.0. That will negate the need for prefixing instance variables with "$cinst.". Boy, I am looking forward to version 4.0!