Tips_todo   >   Notation   >   Notation

Notation

This section is a bit of "catchall" for information about notation not covered in other areas of StudioTips.

Notation is very powerful. Once you get the hang of using notation you'll soon find you prefer notation over the Omnis commands. (At least that's been my experience)

It took me year to discover the full power of the Notation Inspector (F4) coupled with the Property Manager (F6). I wish I had discovered how they work together much sooner! They are an amazing team. Be sure to read more about the Notation Inspector in this section.

SKIPPING $root ... and other parts of the notation string.

You rarely need to include $root in your notation strings. Studio "always" assumes $root if not specified.

If you can avoid "$libs.LibName" in your notation using "$clib" in its place, do so. It will make your code independent of the library name.

Likewise, use $cinst, $cobj, $cfield whenever possible to make your notation less dependent on class or object names.
(See the Notation $c... for a complete list of all the "current" notation.)

Be careful with $cwind and $topwind making sure your code can't fail under various circumstances.

$container

Objects that are inside of any container field have an added property called $container.

$container gives you a reference to the container of the object

Examples of container objects are: Scrollbox, GroupBox, ComplexGrid, TabPane, PagedPane

$desc

$desc has to be one of the handiest tricks I learned for doing notation.

If you want to $add something to a group but can't remember what all the possible parameters are, $decs can be used to figure them out.

Let's say you want to add a local variable to method using notation. You know variable are in the $lvardefs group of the method, but can't remember the parameters for $lvardefs.$add.

Add $desc to the end of the notation you know, and then return the result to #S1, then look at the value of #S1. If you right-click on #S1 you can copy the result to the clipboard and then paste it into a comment line in your code. Handy!

Click the "Run Demo" button to test try this out. The demo code will take you to a breakpoint. Step through the code.

NOTE: A method can't add an $lvar to itself. An instance can't add an $ivar to itself.

$fullname

$fullname gives the full notation path to any valid item reference.

If you have a reference to a class or object, adding "().$fullname" to the reference returns the name property.

You may ask, why did we include the open and close () parenthesis in front of $fullname?

Good question!

You can't always rely on using $fullname without the () prefix. In some cases it will return notation instead of the actual property name. To be safe, I've gotten into the habit of alway prefixing $fullname with ().

Click the "Run Demo" button to see and example.

$name

Omnis use $name for accessing the name property of a library, class, or object.

If you have a reference to a class or object, adding "().$name" to the reference returns the name property.

You may ask, why did we include the open and close () parenthesis in front of $name?

Good question!

You can't always rely on using $name without the () prefix. In some cases it will return notation instead of the actual property name. To be safe, I've gotten into the habit of alway prefixing $name with ().

Click the "Run Demo" button to see and example.

Add Variable

Variables are part of the $?vardefs group. Class variables: $cvardefs, Instance variables: $ivardefs, Local Variables and parameters: $lvardefs. You can find the variable groups using the F4 Notation Inspector.

The syntax for adding a variable using notation is as follows:

Do VarDefsGroupRef.$add('VarName',pkDataType,pkDataSubType,pkDataSubLen,pbIsParamater) Returns VariableRef

You can check F9 > Constants > Data type and Data subtypes for the possible parameters.

Not all data types have a data subtype or data sublength. (See the sample list below.)

The pbIsParameter variable is only applicable to the $lvardefs group and is only needed if you want the variable to be a parameter. Sending 'kTrue' as pbIsParameter will make the variable to be the next parameter for the method. To the best of my knowledge you cannot insert a parameter before an existing parameter, it can only be added to the end of the existing parameters. If you are notationally copying parameters, you first need to make a list of the $lvardefs and sort the $lvardefs group by the $parmno property, then loop through the list of adding the local variables so that they will remain in the same order. Remember to include an extra comma(s) in the list of parameters when adding a parameter that doesn't have a data subtype or data sublength.

Set Reference LocalVarsGroupRef to $libs.LIBRARY.$classes.CLASS.$methods.METHOD.$lvardefs

Do LocalVarsGroupRef.$add('pLineNum',kInteger,kLongInt,,kTrue) Returns VarRef
Do LocalVarsGroupRef.$add('pIsInsert',kBoolean,,,kTrue) Returns VarRef

Note: You can not have a method add a local variable or parameter to itself. The variable must be added from outside of the method. You can not add an instance variable to an instance of a class, the variable must be added before the class is instantiated.

The following is a sample list of the variables and their subtypes. (Provided by Rudolf Bargholz)

$add('Col_Char',kCharacter,kSimplechar,100)
$add('Col_NatChar',kCharacter,kNatchar,100)
$add('Col_Longint',kInteger,kLongint)
$add('Col_Shortint',kInteger,kShortint)
$add('Col_Date',kDate,kDate2000)
$add('Col_Bool',kBoolean)
$add('Col_NumFloatdp',kNumber,kFloatdp)
$add('Col_Fieldref',kFieldreference)
$add('Col_Itemref',kItemref)
$add('Col_Binary',kBinary)
$add('Col_List',kList)
$add('Col_Object',kObject)
$add('Col_Picture',kPicture)
$add('Col_Row',kRow)
$add('Col_Sequence',kSequence)

Adding Date Time variable (Thanks to Terence Young)

$add('Col_DateTime',kDate,kDatetime,16)

Where the sublength of 16 is the 16th item in the $clib's #DFORMS system table's list. Typically, this list starts out with only eight
datetime formats; but can be expanded to include up to 30 datetime formats. It allows for custom date time formats.

Clear instance variables

Do $cinst.$ivars.$sendall($ref.$assign(''))

If you need to clear the instance variables for any instance you can use sendall to clear them.

Thanks to Fred Haislmaier for this tip.

NOTE: The above sendall will blow away your row and list definitions.

Copy Window Object using Notation

You can copy any object and all it's attributes using notation.

1. Set a reference to the source object you want to copy.
2. Add the same object type to the target, returning a reference to it.
3. Step through the attributes group of the source object, setting the target object attributes to the same values.

The sample code below show how to do it.

Copy a Class

Copying a class using notation is very easy. The same code below show you how to do it.

Thanks to Andreas Pfeiffer for this tip.

Do inherited

rhJobs.If you use the return value for Quit method to indicate a true or false result the Omnis command "Do inherited" used to be a problem (pre v3.0), because it always returned kTrue. (This bug has been fixed!)
The notation alternative to "Do inherited Returns FlagOK" is:

Do $cinst.$inherited.[$cmethod().$name]() Returns FlagOK

But now that the bug is fixed, why bother using notation? :-)

Click the "Run Demo" button to prove the theory.

Notation Inspector

Using the F4 Notation Inspector in conjunction with the F6 Property Manager can help you out big time with learning/using/writing notation. It took me over year to figure this out ... had I known it, I could have saved quite a bit of time learning and writing notation in Studio.

Click the 'Run Demo' button to learn how to use the Notation Inspector and Property Manager for writing notation. It will give you a step by step well commented walk through writing notation which actually adds a button and method to the demo window instance.

This demo was a lot of work to put together ... so be sure to try it out. :-)

The Notation Inspector and the Property Manager ... an amazing team!

Thanks to Bob Preston for his email on the list server which opened my eyes to the power of using the Notation Inspector and Property Manager for writing notation.

Thanks to engineering for setting this up so we can use them interactively while stepping through and writing code!

Overloading Properties

While developing StudioTips I ran into snag with the "$destruct" method in my window. I was using a superclass $destruct method to save the last closed size and location of the subwindow class.

The method failed because the subclassed window's $top, $left, $height, $width properties were inherited from the superclass. To make the code work I had to manually overload these attributes for each subwindow.

Not wanting to do this manually, I asked Tech Support for some help. They pointed me to the "$isinherited" property.

Class properties that can be inherited from a superclass have an "$isinherited" property which you can assign using notation. You can override (or inherit) a property by setting the $isinherited property.

Sample code below shows the solution I used to override and then store the subclass window size and location.

Queue set current field

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.

Thanks to Philippe Vanden Broeck for this tip.

Send message to all objects

In the process of doing the demo windows for StudioTips I tripped across an interesting idea.

In the "Lists - $merge" demo I had 3 lists, each with their own $construct which created their own lists. After doing each merge demo I wanted to reset all the lists to their original state.

Behind the Reset button I added a single line of code:
Do $cinst.$objs.$sendall($ref.$construct())

It worked like a charm! You can check it out by clicking the Run Demo button.

Think about it, you could have a special method in all your window objects and with a single $sendall each object with that method could do something or return something. You could control the action take at the object level. There's some interesting possibilities...

Square Brackets in Field Name

For years I thought if I was using [] square brackets in the 'Field name' of a Calculate everything had to be inside the square brackets. For example:

Calculate [con('Field',%N)] as 'Some value'

Much to my surprise, I noticed a posting on the Omnis list server from Wietse that looked like this:

Calculate Field[%N] as 'Some value'

It tested it, and it worked! Much simpler! Thanks Wietse Jacobs.

Now if we could only do the same thing in the 'as' side of the Calculate, dropping the con(), hmm...

Calculate Field[%N] as 'The current loop count value is ',[%N]
vs.
Calculate Field[%N] as con('The current loop count value is ',%N)