| OO purists say you should not have any global variables but as we all
know you do not always have time to be pure. In most applications you normally have a few
global declarations, usually some kind of an application manager or maybe an object
request broker. Well if you export a PowerBuilder object an look at its source near the
top of the code is a line that looks like:
global type u_ken from userobject
Which means that all objects created within the PowerBuilder painters have an automatic
global variable of their type and name created. This is used by PowerBuilder to solve the
references within your source objects but we can take advantage of this undocumented
feature and just create an object of the correct type into this automatic global variable:
u_ken = CREATE u_ken
If you stop and think about it, PowerBuilder uses these variables itself at run time.
For example when you say Open( w_mywindow ) the window w_mywindow is instantaited and its
handle it stored in the global variable w_mywindow of type w_mywindow. This is how
PowerBuilder knows the window is already open when you try to open it again using the same
name, it also why you have to use a more complicated version of the Open command to open
multiple copies, as there is only one global variable called w_mywindow in the
application. |