Gui4Cli How? Reusing code

  • up
  • down

Gui4Cli Libraries & reuse of code with Gui4Cli

Gui4Cli talk:
a "Gui" is in this part of the world either
- a Gui4CLi program with a GUI and its own executing code,
- a Gui4Cli program with a GUI mainly using a lot of Cli commands
- a Gui4Cli program with a GUI interfacing (with arexx or directly ) one or more complicated programs (eg CygnusEd, OWB&IBrowse&Netsurf&FireWolf)
- a Gui4Cli program with no GUI used by any of the above

Having more than 10, 20 gui's loaded at the same time is a normal situation in my Gui4Cli working environment. Not all are open at the same time, some are pop-up gui's others may as said, not even have a window declared

After a while of programming with Gui4Cli it becomes clear that you reprogram a number of command sequences over and over again, with small changes.
The idea of standardising them and make the standardised versions available to other guis is an obvious one. It is one of the easiest to implement in Gui4Cli. I would be surprised to hear that it is easier in another language.

The reason why, is that you can address any subroutine of any loaded gui.
Gosub #this Mysubroutine Arg1 Arg2 ...

is the normal call for a subroutine #this is translated by the interpreter into your Gui's name

Gosub ThatOtherGui.gc ItsSubroutine  Arg_1 Arg_2 ...
works just as well if ThatOtherGui.gc has been loaded.

So a good start is dissociating the candidate sequences from their gadgets (Events) to which they are attached and put them in a named subroutine.
In fact taking an habit of doing this for all Events and all you guis is still a better start.
(I am in the process of doing that retroactively for all my gui's )

  1. xMyEvent
  2. MyCommand1
  3. MyCommand2
  4. ...
  5. Mycommand x

should become

  1. xMyEvent
  2. Gosub #this MyRoutine1
  4. xROUTINE MyRoutine1
  5. MyCommand1
  6. MyCommand2
  7. ...
  8. Mycommand x

Now all you have to do for those you want to have at hand at all times is tot put them together in a file
and have

as first characters on the first line.

Your reusable library has been created.
Of course you may want to have more than one such files assembling routines that share some common concern.

In fact the Gui4Cli3.8 archive comes with a number of such 'routine files'
Two other Gui4Cli features make the use of other gui's routines easier:

- addressing variables of other guis is possible
$ThatOtherGui.gc/ItsVar will contain the value of ItsVar defined in ThatOtherGui.gc (where its content is addressable as $ItsVar)

- sharing variables between a number of guis is possible too with the global command (not attached to any Event)

VARPATH VariableSearchPath


> VarPath "ThatOtherGui.gc/ThatOtherGui1.gc"
(See for more info)


Blog post type: 


stephenix1015's picture

Apart from the ReAction window we have defined and used as our AppWindow, we have two other resources to dispose of when the program has run its course: the application port and the hook.-Arthur van der Vant