Application Logic
Description
When an application uses the Grid Management Library (GML) to interface with a grid control, the GML must be set-up based on parameters provided by the application.
Prototype topic: GML concepts provides additional information Relating to the GML.
a: GML Init:
Following is the code sequence used to initialize the GML for the Attached file prototype program gml_af):
|
b: LUM Init:
The GML can be configured to associate a list type control, such as a List button or list edit, with a particular event that occurs on a specific column within a main grid cell.
This feature provides the capability to temporarily show, at the location of a main grid cell, a list type control to be used to look-up and select information from a list of choices presented within the control.
The GML administers the tasks associated with moving, sizing, showing, and hiding the look-up control. The portion of the GML that manages these tasks is referred to as the GML look-up manager (LUM).
In this prototype, when the grid focus (highlighted cell) is on a cell in the item id or description column, pressing f8 or right clicking on the cell will display a listedit control that can be used to select an item id from a list of selections.
The following code segment initializes the look-up manager:
|
c: Attached File Init:
A template named gml_rcd$ is used to interface between the application and the program (gml_f) that manages the reading of the data channel.
This template is obtained by using the GML attached file procedure attach_file. This procedure may be used at any time after the GML has been initialized.
In this prototype, the attached file configuration is set at mode 1, mode 2, or mode 3 by clicking on the appropriate radio button in the mode group box. When a change in mode occurs, the following code is used to set-up the selected attach file mode:
The GML template is prepared and the procedure detach_file is executed to reset all GML variable associated with the attached file feature.
|
The GML template is again prepared, and procedure attach_file is Executed to start the attached file initialization process.
|
After execution of the attached_file procedure, the gml_rcd$ template is returned to the prototype by program GML, at which time the file channel is assigned by the prototype to variable gml_rcd.flag%. In addition, the attached file mode is set, based on the contents of variable gml_rcd.key$.
If variable gml_rcd.key$ is null, then the attached file mode is 1 (the entire file) if variable gml_rcd.key$ contains key data, and variable gml_rcd.key$ does not contain an embedded $00$, then the key data is used as the start key.
The attached file mode is set a 2 (a portion of the file with the full scope undetermined).
When gml_rcd.key$ contains key data, and variable gml_rcd.key$ contains an embedded $00$, then the key data is used as the start key, and end key. The attached file mode is set a 3 (a portion of the file with the scope determined by the start and end key).
The following code assigns the data channel and sets the attached file mode by assigning the appropriate data to variable gml_rcd.key$.
|
The attached file configuration is then initialized in the following line of code:
|
After attached file initialization, program control is Transferred to subroutine gml_f to read the first group of records that will be displayed on the grid.
|
d: Read Cycle:
There are four ways to move through (read) the attached file:
-
By clicking on one of the two visible vertical scroll bars
-
Using the keyboard page up/down keys
-
Using the keyboard arrow up/down keys
-
Selecting previous page or next page from the go to menu bar.
It is important to note that the scrolls bars on the right side of the Grid are not part of the grid, but controls that have been sized and positioned on the grid by program gml_f.
Each time the attached file is initialized, three scrollbars are created.
Depending on the attached file mode, two of the three scroll bars are made visible by program gml_f.
e: Events:
When the GML was initialized (see GML init), the id of the main Grid control (5001) was assigned to variable gml.gr_id%[1]. Accordingly, when the attached file was initialized (see attached file_init), three vertical scroll bars were created. The ids of these controls are equal to the main grid control id -1, main grid control +3, and the main grid control +4.
In the following code segment, which is part of the event queue decoding logic, an event on a scroll bar that is part of the attached file configuration is routed to subroutine gml_f for processing.
|
The following code segment is part of subroutine gml_m. When a grid event is caused by a keyboard arrow up/down or page up/down key press, the event is routed to subroutine gml_f for processing.
|
When a previous page or next page selection occurs from the go to menu bar, the following code segment, which is part of the event queue decoding logic, transfers program control to the gml_f subroutine after assigning the appropriate value to the gml_rcd.flag% variable.
When program gml_f is called by subroutine gml_f, the Gml_rcd.flag% variable is interpreted by program gml_f as if a page up or page down event has occurred from the keyboard.
|
f: Call To GML_F:
Subroutine gml_f calls program gml_f to perform the next read of the attached file.
The quantity of records to read (referred to as the read cycle) and the direction of the reading of the file are based on the type of event that has caused the transfer of program control to this subroutine.
|
g: Read Status:
After calling program gml_f, the status of variable gml.flag% is checked.
If the value is negative, an error has occurred, and a message is displayed by transferring program control to subroutine msgbox. The subroutine then exits after setting the cursor to normal.
If no error has occurred, the value in variable gml_rcd.flag% is checked. If the value is less than 1, then the read cycle has ended and the subroutine exists after setting the cursor to normal.
|
h: Last Record Flag:
If the attached file mode is 2 and the value in gml_rcd.key$ indicates that it is not equal to the current order #, the value in ml_rcd.flag% is set to 1. This flag is used to indicate to program gml_f that the last record to be read has occurred. Program gml_f is then called and the read cycle is terminated when program gml_f exits with a gml_rcd.flag% value of 0.
|
i: Data Substitution:
Changes to line items are stored in the o_line.tmp file, with the type of change stored in the up_log.tmp file. Each time program gml_f performs a read, the key and record data for the latest read are placed in variable gml_rcd.key$ and gml_data$.
The next section of code determines if changes exist, and if so, uses the data from the o_line.tmp file as the data to be formatted and displayed in the grid in place of the data obtained from the o_line file during the reading of the file by program gml_f.
|
j: Template Prep:
Once the data (from either the o_line.tmp file or o_line file) has been placed into the o_line template, the GML template is prepared by calling program gml.
At this point, the colors to be displayed in the row of the grid are determined by switching on the value in variable p_log.action$.
The GML template is then updated with the template colors by using function fncolors$.
|
k: Data Formatting:
Data formatting is the next step in the read cycle, which occurs in subroutine data_prep.
The data_prep subroutine prepares the data for each column in the grid. In some cases the data is placed directly into the gml_tpl.col[c]$ template variable (columns 1, 5 & 8).
In other cases (columns 2, 3, 4, 6, & 7) additional treatment is required.
|
l: Next Read:
After preparing and placing the data into template gml_tpl$, subroutine gml_f branches to the call to program gml_f.
Program gml_f displays the formatted data and performs the next read as required.
|
n: Cycle End:
When the read cycle has concluded, the cursor is set to normal, and subroutine gml_f terminates.
|
o: Storing Changes:
Changes to line item information are made by editing a main grid cell. These changes are validated, then the updated information is stored in the o_line.tmp file.
The subroutine store_changes is used to administer the storing and updating of changes, in the following manner:
The information in template gml_tpl$.col$[1] and gml_tpl.col$[2] are used to construct the file key:
|
The o_line.tmp file is checked first to determine if a previous change to the same record has occurred. If there is a record in the o_line.tmp file, the o_line_tmp$ template is loaded with the record information, and the program branches to the load_changed_info label for updating the o_line_tmp$ record template.
If a record does not exist in the o_line.tmp file, the program switches on the value in the variable add_item_flag%.
When the add_item_flag% value is 0 (the order line information is not being added as new), the o_line_tmp$ template is loaded with information from the o_line file, and then loaded with the changed information.
When the add_item_flag% value is not 0 (new order line being added), the o_line_tmp$ string template is dimensioned based on the O_line_template$, loaded with the appropriate values, and then loaded with the changed information.
|
The changed order line item information is then written to the O_line.tmp file as follows:
11420 WRITE RECORD(F_O_LINE_TMP%)O_LINE_TMP$
All changes to order line items are logged and stored in a mkeyed file named up_log.tmp. This file is used in subroutine gml_f to determine if the record information in the o_line.tmp file is to be substituted for the information residing in the o_line file.
The next segment of code manages the updating of the up_log.tmp file:
|
When a new line item is added, the o_line file must also be updated, as in the following:
|
The remaining code segment performs various routine items, including the updating the grid with row colors indicating an added item.
|
p: Saving Changes:
In subroutine store_changes, changes to line items were stored In the o_line.tmp file. The save_changes routine makes the changes permanent by updating the o_line file based on the information contained in the up_log.tmp file and o_line.tmp file.
|
q: Temp Files Init:
The file_temp_init subroutine is used to clear all changed information that has been stored in files o_line.tmp and up_log.tmp. This subroutine is executed after subroutine save_changes has completed, or after information that changes should not be saved. Additional logic also resets the change_flag% variable, and disables certain menu items.
|
r: Direction Flag:
A new variable, SCROLL_DIR, has been added to the Template GML_RCD$. This variable specifies the direction of the pointer - either forward or backward. If the user scrolls down the grid, the variable returns the number of records that the file pointer is moving forward up to the amount of visible rows. If the number of rows exceeds the number of visible rows, then the variable returns the number of visible rows. The same logic is used for backward direction.