First of all we create a new file like “array.per” with the new screen form:
DATABASE FORMONLY LAYOUT VBOX TABLE { [id | name | age ] [id | name | age ] [id | name | age ] [id | name | age ] [id | name | age ] } END END ATTRIBUTES id = FORMONLY.id, TEXT=”Id”; name = FORMONLY.name, TEXT=”Name”; age = FORMONLY.age, TEXT=”Age”; INSTRUCTIONS DELIMITERS “||” SCREEN RECORD s_arr[5](FORMONLY.id THRU FORMONLY.age)
With “VBOX” we create a vertical align table to display our ARRAY vertically. The screen record is needed to declare how many rows your array has and from which column to the next column it has go. [5] is the rows of our ARRAY.
Compile it with “fcompile -xml array.per”
Then we create our window. Create a new file such as “array.4gl”.
MAIN DEFINE string STRING CLOSE WINDOW screen CALL ui.Interface.loadActionDefaults(”default”) CALL ui.Interface.LoadStyles(”default”) OPEN WINDOW array WITH FORM “m_array” CALL ui.Interface.setText(”Display Array”) MENU “Navigation” COMMAND “Ok” CALL dialog(string) COMMAND “Search” CALL displ_arr() RETURNING string COMMAND “Insert” CALL insert_arr() COMMAND “Exit” EXIT MENU END MENU END MAIN FUNCTION insert_arr() DEFINE sc_arr ARRAY[500] OF RECORD id INTEGER, name CHAR(255), age INTEGER END RECORD INPUT ARRAY sc_arr FROM s_arr.* BEFORE INPUT MESSAGE “BEFORE INPUT. Please fill the form fields.” BEFORE FIELD id AFTER FIELD id MESSAGE “Id have beed changed on row “||ARR_CURR()||”.” BEFORE FIELD name AFTER FIELD name MESSAGE “Name has been changed on row “||ARR_CURR()||”.” BEFORE FIELD age AFTER FIELD age MESSAGE “Age has been changed on row “||ARR_CURR()||”.” AFTER ROW ON KEY (F5) MESSAGE “This is the ON KEY action” AFTER INPUT MESSAGE “End of the ARRAY INPUT” END INPUT END FUNCTION FUNCTION displ_arr() DEFINE sc_arr ARRAY[500] OF RECORD id INTEGER, name CHAR(255), age INTEGER END RECORD DEFINE string STRING LET sc_arr[1].id = “1″ LET sc_arr[1].name = “Max” LET sc_arr[1].age = “32″ LET sc_arr[2].id = “2″ LET sc_arr[2].name = “Mustermann” LET sc_arr[2].age = “12″ LET sc_arr[3].id = “3″ LET sc_arr[3].name = “Jorden” LET sc_arr[3].age = “34″ LET sc_arr[4].id = “4″ LET sc_arr[4].name = “Andre” LET sc_arr[4].age = “56″ LET sc_arr[5].id = “5″ LET sc_arr[5].name = “Mike” LET sc_arr[5].age = “82″ CALL SET_COUNT(5) DISPLAY ARRAY sc_arr TO s_arr.* BEFORE ROW MESSAGE “Please select a row” AFTER ROW ON KEY (F3) MESSAGE “You have selected row number: “||ARR_CURR()||”.” AFTER DISPLAY MESSAGE “Your last row was: “||ARR_CURR()||”.” END DISPLAY LET string = “You have selected the line: “, sc_arr[ARR_CURR()].id CLIPPED, “\nand name: “, sc_arr[ARR_CURR()].name CLIPPED RETURN string END FUNCTION FUNCTION dialog(string) DEFINE string STRING IF string IS NULL THEN LET string = “You have nothing selected” END IF MENU “title” ATTRIBUTE (STYLE=”dialog”, COMMENT = string CLIPPED) COMMAND “Ok” EXIT MENU END MENU END FUNCTION
Compile this example with “4glpc array.4gl -o array.4ae”.
We must define how many rows we want to display in our DISPLAY ARRAY by using SET_COUNT(). In our function “displ_arr()” we create the program array and fill them with content e.g 5 rows and 3 columns. And then we send it to the screen array from the program array with “DISPLAY ARRAY program array TO screen array”.
With the function insert_arr() we have made your screen array editable.