Tips   >   About   >   Hot Tips and Tricks

Hot Tips and Tricks

This section lists my favorite tips and tricks. The tips and tricks are in alphabetic order (Not rated from best to least.)

Break into OK Message

You can break into the method editor and continue stepping through the code from any OK, Yes/No, No/Yes, Prompt for Input dialog window.

When the prompt dialog window is open, depending on your platform press the following key(s):

Tip

Use OK messages to assist with debugging by adding OK messages into your code which report the method being executed and the values you want to watch. Run the process you are trying to debug and at any one of the OK messages you can break into the code and continue stepping through the code in the method editor.

I like to include @DEBUG in the title of any debug OK messages so that I can easily search for @DEBUG to find and remove them later on.

In the StudioTips Browser click the Run Demo button and trying breaking into the demo code.

Change Omnis Command

You can change some of the Omnis commands without losing the calculations or text which you've entered. You can:

You simply select the line of code in the method editor and then click on the other Omnis command in the commands list. Omnis Studio switches the command while retaining the text you've entered.

Change Variable Scope

You can change the scope of any variable by dragging it from one tab pane to another tab pane of the Variables pane in the method editor.

If you are decreasing the scope from a class or instance variable to a local or parameter variable you might get a message that tells you that the scope can't be changed while the class is open. If this occurs use the Window menu to Close Others, then try again.

If you are decreasing the scope of a variable it can't be in more than one method and you must have that one method selected at the time you decrease the scope.

Warning

If you are changing the scope of a class variable or instance variable, make sure you don't have any subclasses which are using that variable! The subclass methods will not be aware of the change. The next time you look at the subclass method, those variables will be prefixed with $cinst. and your subclass method code will be broken.

A situation where this trick comes in useful, is if you have a very long method which you want to break down into several submethods in the same class, or even into a separate object class.

  1. Select and copy a block of the long method to the clipboard
  2. Create the submethod and paste in the code.
  3. Look at the local variables in the variable pane and decide which local variables need to become parameters to be send to the submethod.
  4. Add a letter p prefix to the local variable name. (if you follow this naming convention).
  5. Drag the local variable to the Parameter variables pane.
  6. If you following the coding convention of always returning something from a method, a value or a true or false flag, at the end of the method add a Quit method Returns FlagOrValue.
  7. Back in the long method, delete the copied code and replace it with:

    Do method newMethodName(parameters) Returns RetFlagOrValue

ChromaCoding

Omnis Studio notation methods displays in plain brown text in the method editor.

Custom methods display in bold green text in the method editor.

If you misspell an Omnis Studio notation method it displays in bold green text. Once you pick up on this you can immediately notice if you've correctly or incorrectly typed an Omnis Studio notation method.

; $doesfileexist is displayed in plain brown text.
Do FileOps.$doesfileexist(Path) Returns bFileExists

; Misspelled $doesfilexist (missing the double 'ee') is displayed in bold green text.
Do FileOps.$doesfilexist(Path) Returns bFileExists

Copy Field Properties

I use this trick a lot if I decide to change a kEntry field to a kMaskedEntry field or a kMultiline field.

  1. Select the kEntry field.
  2. Press F6 to open the Property Manager.
  3. Right-click in the blank area of the Property Manager window below the last property and select Copy Properties. This copies the field's properties to the clipboard.
  4. Move the kEntry field away from its current location on the window.
  5. Drag a kMaskedEntry or kMultiline entry field out of the Component Store anywhere onto your window class. The field will be selected.
  6. Right-click in the blank area of the Property Manager window and select Paste Properties. A warning message appear, click Yes. All of the applicable properties from the original kEntry field will be copied to the selected field. The field will move to the exact location of the kEntry field before you moved it. (That's why we moved the kEntry field after copying the properties.)
  7. If there are any methods behind the kEntry field, you will need to copy and paste those methods to the new field.
  8. Delete the kEntry field.

Current Notation

When and wherever possible and applicable use $clib, $cinst, $class, $cclass. $cobj, $cfield, $cmethod, $crecipient, $ctask, $cwind, $topwind in your notation. Your notation strings will be much shorter and much more flexible. See the Notation section under the StudioTips group.

Cycle Through Windows

You can cycle through the open IDE windows using a shortcut key combination.

This is very handy when you have multiple method editor windows open and are comparing or copy and pasting code from one class to another.

Drag Copy Fields

You probably already know about this trick because it is used in lots of drawing program... but in case you don't here it is.

To copy an existing field in a window.

  1. Select the field(s).
  2. Hold down the Ctrl key (Windows) or the Opt key (Mac).
  3. Drag the field(s) to a new location on the window. When you release the mouse Omnis Studio copies the dragged field(s) to the new location.

Edit Code as Text

You can commnet out a line of code in the method editor, edit the code as text, and then uncomment the line of code.

A couple of situations where I use this trick:

The steps for editing code as text are shown in the following example.

  1. Select the line of code you wish to edit.

    Do iList.$search($ref.ColName=Value,1,0,0,0) Returns LineNum
    If LineNum
       ; Do something
    End If

  2. Press Ctrl/Cmnd+; to comment out the code.

    ; Do iList.$search($ref.ColName=Value,1,0,0,0) Returns LineNum

  3. Change the commented out code.

    ; If iList.$search($ref.ColName=Value,1,0,0,0)

  4. Press Ctrl/Cmnd+: to uncomment the code.

    If iList.$search($ref.ColName=Value,1,0,0,0)
       ; Do something
    End If

F9 Catalog

The F9 Catalog is loaded with Constants, Functions, and other goodies which you need to know about when writing code. A very cool feature of the Functions is that you can drag any function along with its parameters directly into your code.

Be sure you have tooltips enabled! Hovering over a function or other item displays a tooltiip with more information. Right-click on the Catalog to set it and then right-click and Save Window Setup after you have it set.

Find and Replace Selected Lines

You can use the Omnis Studio Find and Replace tool on selected lines in the method editor. As situation where I use this trick is if I copy a block of code from one method to another, but after copying the code I see that one of the variables used in the pasted in section of code needs to be change to the name of a local variable already included in the existing method. The steps for changing the variable name in pasted section of code area as follows:

  1. Select the pasted in lines of code in the code list of the method editor.
  2. Press Ctrl/Cmnd+F to open the Find and Replace window.
  3. Enter the old variable name in the Find field.
  4. Enter the new variable name in the Replace field.
  5. Check the following checkboxes: Match whole words only, Use selected method, Select lines only.
  6. Click the Replace All button.

Find and relace selected lines... a handy feature of OMST!

Tip

You can remove selected Find and Replace log lines by right-clicking and selecting Delete Selected Lines.

Incorrect Variable Case

After you enter a line of code Omnis Studio automatically corrects the case (upper or lower) of any characters in variables you type in your code to match the declared variable.

If you have variable named iBooksList and you enter ibookslist in your code, Omnis Studio will change ibookslist to iBooksList after you press the Enter key or move to a different line in the code list.

If you are editing an existing line of code, you can intentionally type the variable name in all lower case characters and then watch as you press the Enter key to make sure Omnis Studio changes the case. If the case is changed you know you've correctly entered the variable name.

; There is no variable declared named 'iBookList' (singular)
Do ibooklist.$search(kTrue)

; There is a variable named 'iBooksList' plural.
; After I change 'ibooklist' to 'ibookslist' and press the Enter key
; Omnis changes the case to match the declared variable.
Do iBooksList.$search(kTrue)

Interface Manager

If you aren't using the Interface Manager, then you are missing a powerful tool in Omnis Studio which can assist you greatly in writing your code.

The Interface Manager lets you look at all the public methods of a class, their parameters, and description.

You can drag methods from the Interface Manager directly into your code along with the list of parameters.

To learn more, go throught the StudioTips Tutorials. The time you take to go through the tutorials will pay back in the time you save over the next month of writing your own code.

Jump to Line

Omnis Studio allows you to find and jump to lines of interest in the Trace Log list, Find & Replace list, and Omnis Commands list:

  1. First, click in the list to move the focus to the list.
  2. Type an asterisk followed by the search criteria (Example: *do m, *$add). The line containing the first occurrence will immediately be selected.
  3. Use the plus (+) or minus signs (-) to move to the next or previous occurrence.
  4. A single press of the backspace key, or clicking again in the list will reset the search.
  5. You can use wild cards any number of times as in *$active*kfalse

Jump to Superclass Method

If are in the method editor of a sublcass and want to look at the code in the superclass here are a few tricks for getting to the superclass method.

  1. If the subclass method is not yet overridden, simple double-click anywhere in code list of the method editor. Omnis Studio will open a new method editor window with the superclass method selected. After viewing or editing the superclass method, you can simply close the method editor window to return to the subclass method.
  2. If the subclass method is overridden and you have a Do inherited Omnis command anywhere in the subclass method, select the Do inherited line in the code list and press F8. Omnis Studio will open a new method editor window with the superclass method selected. After viewing or editing the superclass method, you can simply close the method editor window to return to the subclass method.

    Tip

    If I don't have a Do inherited in the overridden method code, I will often add one at the end of the method after a Quit method command.


    ; Subclass method code of an overridden superclass method.
    Do iList.$definefromsqlclass('SomeTableClass')

    Quit method kTrue

    ; Include this line AFTER the Quit method.
    Do inherited
    ; Select the above line and press F8 to jump to superclass method.

Menus on-the-fly

Instead of creating a menu class and manually adding menu lines for each and every menu in your application, create all your menus on-the-fly! See the Menus section in the StudioTips - GUI group.

Moving Fields to a Different Tab

If you want to move some of the field from one tab to another tab of a tab pane object.

  1. Select the fields you want to move.
  2. Drag the fields so that the mouse pointer is over the tab you want to move the fields to.
  3. Press the Ctrl/Cmnd key and Omnis Studio will switch the tab pane to that tab without deselecting your fields.
  4. Continue dragging the fields to the location you want them on the now current tab and then release the mouse button.
Tip

If you hold down the Ctrl/Opt key while dragging the fields, they will be copied to the other tab.

Notation Errors and $cando

If you want to catch errors in your notation be sure to set the library preference $reportnotationerrors to kTrue for every one of your libraries.

If you have calls to custom methods which may or may not exist, use $cando to test for the existence of the method before calling it. This will avoid hitting a notation error for those optional custom method calls.

; Optional call to a custom method which might not exist.
If $cinst.$OptionalCustomMethod.$cando
   Do $cinst.$OptionalCustomMethod() Returns FlagOK
End If

Notation Helper

Set the notation helper to respond really, really, fast so that you don't have to pause for it to help you when writing your code.

  1. Open Omnis Studio Preferences
  2. Select the General tab.
  3. Set $notationhelptimer to 50
This tip speeds up my coding, reduces typos, and saves me a lot of keystrokes!

Notation Inspector

If you aren't using the F4 Notation Inspector, then you are missing one of the more powerful tools in Omnis Studio which can assist you in writing your code. Coupled with the F6 Property Manager they a great team. The Notation Inspector lets you brower everything in your Omnis Studio application and the F6 Property Mananger tells you all the methods and properties for anything you select in the Notation Inspector.

You can drag properties or methods from the Property Manager directly into your methods.

To learn more, go throught the StudioTips Tutorials. The time you take to go through the tutorials will pay back in the time you save over the next month of writing your own code.

Ping Method

I like to include the following $ping method in the class methods of all my object, window, and table classes.

; Return true. Open OK message if not(pbSilent).
If not(pbSilent)
   OK message Ping (Icon) {$ping message received by... ////$lib: [$cclass.$lib().$name] ////$cclass: [$cclass().$name] ////$cinst: [$cinst().$name] ////$container: [$cinst.$container().$name]}
End If
Quit method kTrue

If you are debugging and want to test sending a message to a class instance the $ping method is a handy way to jump into the class instance's class methods.

Do $clib.$windows.wWinClassName.$openonce() Returns rWin
If rWin
   
   ; Test sending a ping message to the window.
   Do rWin.$ping() Returns FlagOK
   
End If

I sometimes use the $ping method with the pbSilent parameter set to kTrue in order to test for a valid instance in my runtime code as follows:

; Dynamically point a variable to an object class instance.
Do $clib.$objects.oObjectName.$new() Returns oObjInst

; Test for a valid instance using the $ping method.
Do oObjInst.$ping(kTrue) Returns FlagOK
If not(FlagOK)
   OK message Error (Icon) {Unable to $ping the object instance.}
Else
   ; Continue
End If
Quit method Flag

Programmer Tests

The StudioTips Tips menu has some handy menu lines which you can use for testing code.

  1. Programmer Test Method - selecting this menu line takes you too a Breakpoint in the menu's $event method. Write any test code you below the Breakpoint and the run the code.
  2. Programmer Test Window - selecting this menu line opens the wProgrammerTests window class where you can drag fields from the Component Store and test various window related objects and methods.
Consider both of these programmer test menu lines as your code testing scratch pad. Alway nearby and ready to use!

Pushbutton Shift+Click Breakpoint

This trick is great a great help for developer testing and debugging! I put the following code in the $event method of all my pushbuttons.

On evClick
If #SHIFT
   Breakpoint
End If

This allows me to hold the shift key down when I click on any pushbutton or toolbar button and very easily break in and start stepping through the code.

To save having to copy and paste the code into each pushbutton, you can add the code to the pushbutton in your Component Store as follows:

  1. Select and double-click any window class in the F2 Browser.
  2. Press F3 to open the Component Store.
  3. Right-click anywhere on the Component Store window > select Show Component Library in Browser.
  4. F2 Browser > select ComponentStore library > double-click the _FieldComponents window class.
  5. Double-click the Push button field to get to the field methods.
  6. Enter the following code in the $event method of the Push button field.

    On evClick
    If #SHIFT
       Breakpoint
    End If

  7. Close the Method Editor.
  8. Close the _FieldComponents window class.
  9. Click the Hide Component Store button in the F2 Browser.

The next pushbutton you drag out of the Component Store will include the code you just added to the $event method.

I also include the If #SHIFT Breakpoint End if code in the $event method of my tab pane objects, just after On evTabSelected. This allows me to break into my code by shift+clicking on a tab.

An extension of this trick is to include on all your window classes a tiny Programmer Test pushbutton which is only visible to developers. You add a $construct method to the pushbutton and put the following code in the button to hide it from non-developers.

; $construct method of Programmer Test pushbutton
; Hide the pushbutton from non-developers.
If sys(2)<>1
   Do $cfield.$visible.$assign(kFalse)
End If

Selecting Fields in a Container

Trying to select a group of fields which are inside a container field (Paged Pane, Tab Pane, Group Box, Scrollbox) can be a real pain. If you try to drag a rectangle marque around the fields, the container field gets selected and you never get a chance to draw the marque rectangle around the fields inside the container.

Hold down the Ctrl/Cmnd key and you will be able to drag a marque around the field inside the container field without selecting the container field.

Top Window Methods

Do you ever want to get to the methods of a window instance without breaking the instance?

The StudioTips Top Window Methods menu line in the Tips menu does this for you.

If you are reading this tip in the StudioTips Browser, press Ctrl/Cmnd+Shift+T right now. This is the shortcut key combination for the Top Window Methods menu line. (Think of it as an alternate to Ctrl/Cmnd+T)

Once you are behind the window instance, you can select a method, set a red breakpoint, then close the method editor and run the method from the instance. When code execution reaches the red breakpoint the method editor will open at that point and you can continue stepping through the code.