Q: Which form will Ensign act on when Window = 0? The GetVariable() command crashes if it is called on a non-chart object. I have encapsulated the GetVariable commands in my own wrappers and am trying to apply a test to determine whether the form referenced by Window is a chart or not. Long story short is that I have found some checks that work most of the time but still fail under circumstances that I cannot fully quantify. My main challenge is that when Window=0 then I don't know which of the screen.forms[] will actually be acted upon by Ensign.
Is it possible to write a function that returns the screen.forms[] index that matches the same form referenced by the Window variable i.e.
A: The ActiveMDIChild which would be in the 0 index position of the screen.forms array. This array is the windows operating system z-order list and it does change as you give other windows focus. The window with focus moves to the 0th position and others push down. This is the same order you see on menu Window at the bottom of the menu listing in Ensign.
Q: Ah, screen.forms[] equates to the z-order list, I did not realize that. I am still a little confused on how this works though. Take a scenario where I have two charts open, Chart A has an ESPL 51 study attached, Chart B has no ESPL studies but it does have the focus i.e. I understand that Chart B is the ActiveMDIChild.
The second question I have is when a bar close event occurs on Chart A I will receive and ESPL code of 51 and Window = 0. Does this mean that Chart A has moved to screen.forms[0] position and bumped every other form down?. As you can tell I am still a little confused. I appreciate your patience in helping me understand.
WINDOW: integer;
Description:
Window is used internally by several functions to know which window to work with.
Window must be set before a function which uses the window variable is called.
Window is internally set by the FindWindow, Chart, and Quote functions.
Window can be assigned or read by the user as a regular variable.
Window is set to zero to default to the window which called the script.
Example
Chart('IBM.D'); {The Window variable points to the Chart}
TextOut(5,10,'Ensign Software'); {TextOut uses Window to print on the Chart}
A user study will set Window to zero and internal pointers to the calling chart and study. When Window=0 the calling chart pointers are used to reference the chart and the study. Internally we act on Window>0 to map Window-1 to the z-order list for MDIChildren[x] where x is in the range of 0..pred(MDIChild.count)
Use FindWindow to set Window variable to the index position on the MDIChildren list, and Window will be Index+1 because of the above offset by 1 so that our Window=0 as special treatment to use the calling chart pointers. Calling chart does not change its position on the z-order list.