Copying the key values of the first selected record in a table

table_first_selected_key()

Copy key values of first selected record


SYNTAX

table_first_selected_key(table_id)

This function is for use with tables whose source object is a file.

It copies the key values of the first selected record into the default buffer of the source file. The default buffer has the same name as the file, and is allocated to it automatically. If the source object is a secondary index, the values copied are the main index key, not the secondary index key.

The program can then read the record from the file using read[u], or use the key values for any other purpose.

Once this function has been called, calls to table_next_selected_key() read in the key values of the next selected record.

Returns zero (OKAY) if there is a selected record.

Returns a non-zero value if there is no selected record, or if the table source object is not a file. In this case the key fields in the file’s record buffer remain unchanged.


EXAMPLE

When the OK button is pressed in a List window, read the main index and display the selected record. This method is used in programs generated by proggen:

!function OKListButEvent(EventCode, Object) {
     if (EventCode <> EV_BUTTON_CLICKED) then return
     DisplayListRec()
     return CANCEL_DIALOG
}

!function DisplayListRec() {
     if (table_first_selected_key(ListTable) = OKAY) {
          if (ReadRecord(_UNLOCK, "Main") = OKAY) {
               sync_indexes FILE_TESTFILE
               Display()
          }
     }
}

RELATED TOPICS

Tables