Originally Posted by spartacus
Thanks this board I know the above function, and use it :-)
But does anybody know where it is documented? I can't find it in any of my refernces, and also not in the "undocumented functions"-Thread here in the board. Where ist it?
BaanERP Programmers Guide
Processes, process groups, and main windows
A process consists of a program object, a date, and a state. A process that has been started can be in any one of the following states:
The process is in the running queue. It has been scheduled to run, or is ready to be scheduled.
The process is in the blocking queue. It is waiting for input.
The process is in the sleeping queue. It has been suspended and requires an external action to wake it up again.
The process is in the terminating queue. It has ended but not all its resources have yet been removed.
Each process stores information about the current main window, the current menu, and current character window. Other information about display objects is not directly available to it.
A process group is a group of related, interdependent processes. One process is the group leader. Child processes are started by the leader or by one of its children. All processes belong to a process group.
The following are some of the characteristics of process groups:
Each process group has its own event queue. Events are sent to the process group, not to individual processes.
When one process within a group starts a child process, the child process is automatically placed in the same process group as its parent. However, you can use the function set.pgrp() to place the process in a different process group.
When a process is killed or ended, its parent is automatically awakened, unless the parent and child are in different groups.
You use the grab.mwindow() function to set the process group to which a main window sends its events. After calling this function, all events that occur in the main window are sent to the specified process group.
A main window acts as the frame window for both sessions and 3GL applications. It is used for starting processes and for creating graphical and character windows. It is not used directly for handling user input or displaying program output. Usually, a main window consists of a border, title bar, menu bar, status area, control menu box, sizing controls, and a work area. The objects used by an application for user interaction are created within the work area of a main window and are managed by that main window.
Each process can have zero, one, or more main windows.
Process groups and main windows
Process groups and main windows are used:
to ensure unambiguity of input focus
to keep related processes dependent
to enable parent and child processes to be independent of each other
Unambiguity of input focus
To ensure that there is never any ambiguity as to where the events generated by a particular window are sent, when you create a main window, you define a single process group to which that main window sends its events. You do this with the grab.mwindow() function. After calling this function for a main window, all events that occur in that window are sent to the specified process group. In principle, there is only one running process in a process group at any time; so the events are sent to that process.
In principle, each process could have its own event queue. However, there are a number of situations where this would cause problems. For example:
When the input focus is on an input field and the user zooms to another process to select a value. In this case, the parent process is moved to the sleeping queue and will be awakened when the child process ends.
However, if the user types in the input field after the zoom process has started but before the zoom process has created its own windows, the characters typed are sent to the sleeping process and not to the zoom process for which they were intended. When the windows of the zoom process appear, the user must then restart the selection. However, when the zoom process exits, the characters sent to the parent process are displayed in the input field and not those entered in the zoom process. This is because, when awakened, the parent process finds those characters in its process queue.
A similar problem can arise when a uses ends a number of nested processes by repeatedly pressing the EXIT key and also when processes are synchronized by using bucket functions.
These problems are avoided by enabling related, interdependent processes to share the same process group (and so the same event queue).
Keeping related processes dependent
When a process is started by the functions activate(), act.and.sleep(), or wait.and.activate(), by default the new process inherits the process group and main window of its parent. The parent process is moved to the sleeping queue will be awakened automatically when the child process ends.
The following diagram illustrates this.
A process with the same ID as its process group is referred to as the group leader. For the group leader, the predefined variable background is set to FALSE, For child processes, this variable is set to TRUE.
A process group keeps track of the number of processes that belong to it. When no processes remain in the group, the group is automatically destroyed. You can destroy all processes in a particular group simultaneously by calling kill.pgrp().
Making related processes independent
When a process starts a child process, by default the child process inherits the process group and main window of its parent, and the parent is suspended until the child exits. However, it is possible to create a new process group and main window for the child process and so keep the parent and child processes independent. The following diagram illustrates this.
The code for disconnecting a child process from its parent can be included either in the parent process or in the child process. In the following example, it is included in the parent process.
old.mwindow = current.mwindow()
new.mwindow = create.mwindow( title, mode, flags)
change.mwindow( new.mwindow )
child.pid = act.and.sleep( program.name, arglist )
if child.pid then
set.pgrp( child.pid, child.pid )
grab.mwidow( new.mwindow, child.pid )
reactivate( child.pid )
change.mwindow ( old.mwindow )
destroy.mwindow( new.mwindow )
In this example, the parent process first creates a new main window for the child process. It then starts the child process and calls set.pgrp() to place the child process in a different process group. By specifying the same ID for the process and the process group in the set.pgrp() call, a new process group is automatically created with the same ID as the process. The process becomes the leader of the new process group. The parent process then calls grab.mwindow() to link the new process group to the new main window.
In this example, it is important to start the child process with act.and.sleep() and to reactivate the process only after it has been placed in the new process group. If the process is started with activate(), and a context switch occurs immediately after the child process is started, then the process would be scheduled with the incorrect process group.
Note that if a process is moved to another process group, it will be impossible to switch it back to the original group if that group is destroyed in the meantime.
Multitasking and the GUI