Edit Tables: An Example of Displaying All Table Data (Functions/Subroutines/Programs)
Created at 18 JUN 1997 04:33PM
Often times it is handy to have an edit table that displays all values for specified columns of a certain data source. Because OpenInsight s native tables allow multi-value fields, the Edit Table control doesn t automatically display all data just by being on the form and being connected to a table.
The following are two methods of displaying all data in an edit table. The edit table is not associated with a data set, because any reads on the data set would rewrite the edit table so that it showed the current record. A way to workaround the table showing up-to-date values is calling the display routines when data in the actual tables is changed. These edit tables cannot be used to enter data without more script.
The first example deals with a table having no multi-value fields. It will display three columns of data, ordering by the first column, which is also a keyed field.
/*** On something like the OMNIEVENT of the Edit Table
* Uses a table named 'FRIENDS' and sorts by the keyed field 'NAME'
* NOTE: 'FRIENDS' is the author s own creation and won t be found
* in any example applications
***/
EOF = 0
Keys =
NameList =
Row =
Data =
*** sorts the column 'NAME' and sets NameList with this sort info
*** loop to get keys
*** reads next key value using NameList and stores in Name
*** Then stores each Name in Keys structure, delimited by @FM
select 'FRIENDS' by 'NAME' setting NameList then
loop
readnext Name using NameList then
Keys←1> = Name
end else
EOF = 'TRUE'
end
until EOF
repeat
end
i = 1 /*** to index Keys array ***/
*** Opens 'FRIENDS' table to table variable 'Handle'
*** Loops to read a row for each key value into variable 'Row'
*** Stores row info into variable Data, rows delimited by @FM,
*** columns delimited by @VM. This fits the format of the
*** LIST property for Edit Tables
open 'FRIENDS' to Handle then
loop
read Row from Handle, Keys<i> then
Data←1> = Keys<i>:@VM:Row<1>:@VM:Row<2>
end else
Row =
end
i += 1
until Row =
repeat
end
*** Assign Data to the LIST property of the edit table, which will
*** fill in all the values
*** The following is shorthand notation for the function Set_Property
*** The equivalent is:
*** rslt = Set_Property(@WINDOW:'.EDIT_TABLE_1', 'LIST', Data)
.EDIT_TABLE_1→LIST = Data
RETURN 0
The next example does the same thing, but the third column is a multi-value field.
/*** NOTE: The table, 'HOBBY' used in this example, is the author s
* own creation, and does not appear in any example application
***/
declare function Read_Column
EOF = 0
Data =
Keys =
Row =
*** This equate will be for formatting the multi-value data so that it
*** lines up in the correct columns when being output to the edit
*** table
EQU ThirdCol TO @VM:@VM
*** Open table 'HOBBY' to variable 'Handle'
*** GET KEY VALUES and store in 'Keys' array
*** The key values of this table are on a SEQKEY field, so they are
*** already sorted.
open 'HOBBY' to Handle then
select Handle
loop
readnext KeyVal then
Keys←1> = KeyVal
end else
EOF = 'True'
end
until EOF
repeat
end
i = 1 /** to index Keys array **/
*** Read row data for each key value in 'Keys' array and store in 'Row'
*** Set up variable 'MVCol' to hold multi-value data formatted to work
*** with LIST property of edit table
*** Store row data in 'Data' array
loop
read Row from Handle, Keys<i> then
MVCol = Row<2,1>
j = 2 /** to index field in multi-value column **/
loop
until Row<2,j> =
MVCol := @fm:ThirdCol:Row<2,j>
j += 1
repeat /** end inner loop **/
Data←1> = Keys<i>:@VM:Row<1>:@VM:HobCol
i += 1
end else /* end THEN of Read statement, begin ELSE */
Row =
end
until Row =
repeat /** end outer loop **/
*** Assign Data to the LIST property of the edit table, which will
*** fill in all the values
*** The following is shorthand notation for the function Set_Property
*** The equivalent is:
*** rslt = Set_Property(@WINDOW:'.EDIT_TABLE_2', 'LIST', Data)
.EDIT_TABLE_2→LIST = Data
RETURN 0