Example 3: DISPLAY ARRAY using modification triggers
Database table definition:
CREATE TABLE customer
(
id INTEGER NOT NULL PRIMARY KEY,
fname VARCHAR(50),
lname VARCHAR(50) NOT NULL
);
INSERT INTO customer VALUES ( 101, "John", "Calagan" );
INSERT INTO customer VALUES ( 102, "Mike", "Torn" );
INSERT INTO customer VALUES ( 103, "Omer", "Winston" );
The "shop.sch" schema file:
customer^id^258^4^1^
customer^fname^13^50^2^
customer^lname^269^50^3^
Form definition file
"custlist.per":
SCHEMA shop
LAYOUT
TABLE
{
Id Name LastName
[f001 |f002 |f003 ]
[f001 |f002 |f003 ]
[f001 |f002 |f003 ]
[f001 |f002 |f003 ]
[f001 |f002 |f003 ]
[f001 |f002 |f003 ]
}
END
END
TABLES
customer
END
ATTRIBUTES
f001 = customer.id;
f002 = customer.fname;
f003 = customer.lname;
END
INSTRUCTIONS
SCREEN RECORD srec(customer.*);
END
Program source code:
SCHEMA shop
MAIN
DEFINE arr DYNAMIC ARRAY OF RECORD LIKE customer.*
DEFINE cnt, ofs, len, row, i INTEGER
DATABASE shop
OPEN FORM f1 FROM "custlist"
DISPLAY FORM f1
DECLARE c1 CURSOR FOR
SELECT id, fname, lname FROM customer
LET cnt = 1
FOREACH c1 INTO arr[cnt].*
LET cnt = cnt + 1
END FOREACH
CALL arr.deleteElement(cnt)
DISPLAY ARRAY arr TO srec.* ATTRIBUTES(UNBUFFERED)
ON UPDATE
INPUT arr[arr_curr()].* WITHOUT DEFAULTS FROM srec[scr_line()].* ;
ON INSERT
INPUT arr[arr_curr()].* FROM srec[scr_line()].* ;
ON APPEND
INPUT arr[arr_curr()].* FROM srec[scr_line()].* ;
ON DELETE
MENU "Delete" ATTRIBUTES(STYLE="dialog",
COMMENT="Do you want to delete the current row?")
COMMAND "Yes" LET int_flag = FALSE
COMMAND "No" LET int_flag = TRUE
END MENU
END DISPLAY
END MAIN