Re: Using Do Code Method to make static method calls: safe practice?
Hi Andrea,
I’ve done this for years, and I seem to remember being told by support/engineering that it would not likely break in future. The method checker will complain only because it wants Do code method to be referencing a Code class.
I think of it as ‘Do Class method’ (what you’re calling static methods) and I use it to do self-contained prompting windows that can be called modally with a one-liner. I name these methods using a ‘$_’ prefix to remind me that these are class methods, which cannot use instance (or task) variables because they’re called from a non scope. So as a rule my class method will obtain an instance by constructing it, or finding it by name in $iwindows, or $itasks. Then it calls into the instance where the instance and task variable scopes are valid.
A class can be written to have several entry points to get different behaviors, maybe using different panes in different modes, or showing more or fewer objects. My custom message window has separate entry points for OK, Yes/No and No/Yes messages. All the mechanics are kept self-contained in the window class, and the class methods are the public interface, telling you all you need to know about how to use the class.
This runs a modal instance of the wGetShortcut class in one line.
Do row.$define(shortcut,expansion)
Calculate row.shortcut as myShortcut ;; set up editable values going in
Calculate row.expansion as myExpansion
;
; call the $_editShortcut class method to open the window, run enter data, and close it with OK or cancel
Do code method wGetShortcut.$_editShortcut (row) Returns #F
If flag true
Calculate myShortcut as row.shortcut ;; fetch values coming out
Calculate myExpansion as row.expansion
. . etc. .
So Peter asked “Why would you want to do that?” and That’s why. I think class methods are a valid OO concept that Omnis is able to support using Do code method.
But I could be wrong.
Kelly
Selected methods for window class ‘wGetShortcut’
##### Method ‘$_editShortcut’ #####
No. Parameter Type
1 pShortcutRow Field reference
No. Local Variable Type
1 okayed Boolean
2 wRef Item reference
No. Method text
1 ; (this is the class method)
2 Do $clib.$windows.[$cclass().$name].$open() Returns wRef ;; make an instance
3 Do wRef.$runWindow(pShortcutRow) Returns okayed ;; call into the instance
4 Do wRef.$close() ;; dispose the instance
5 Quit method okayed
##### Method ‘$runWindow’ #####
No. Parameter Type
1 pShortcutRow Field reference
No. Method text
1 ; (this is the instance method)
2 Calculate iShortCutRow as pShortcutRow ;; row defined for fShortcut
3 Do $cinst.$redraw()
4 Enter data
5 If flag true
6 Calculate pShortcutRow as iShortCutRow
7 Quit method kTrue
8 End If
9 Quit method kFalse
No method errors found
_____________________________________________________________
Manage your list subscriptions at lists.omnis-dev.com