table.RECORD_TO_VARS Function
Syntax
Arguments
- vars
Pointer variable that is populated with the values of the current record's fields.
- flagTrimTrailingSpaces
Specify if trailing spaces in each field should be trimmed. Default value is .t..
Description
convert a record to a set of variables in vars
Discussion
The <TBL>.RECORD_TO_VARS() method populates the Vars pointer variable with the values of the current record's fields.
Example
This example lists field names and the values in the current record.
dim vars as P dim tbl as P tbl = table.open("customer") tbl.record_to_vars(vars) ? vars = firstname = "Aaron" lastname = "Brown " ....
This more complex example retrieves the field names and values of the current record, then generates the appropriate DIM statements for each variable. First, get the data from the current record. Note, you must dim myptr in the same scope that you are passing into the function, otherwise you will have two different myptr variables in different scopes. In this case myptr is local and the call to GetFieldnamesToPointers() leaves the scope parameter blank.
dim myptr as P dim cResult as C dim tbl as P tbl = table.open("customer") tbl.record_to_vars(myptr)
Next, generate the code that will dim the variables.
cResult = GetFieldnamesToPointers("customer", myptr, "") IF cResult = "" ' success showvar(properties_enum(myptr)) ELSE ui_msg_box("Error occurred", cResult) END IF
This function calls GenerateDIMLine for each variable.
FUNCTION GetFieldnamesToPointers as C (TableName as C, ptr as P, Scope = "Shared") DIM code as C DIM fldlist as C DIM cResult as C fldlist = table.EXTERNAL_FIELD_NAME_GET(TableName, "N|t|T") code = *for_each(tag, GenerateDIMLine(word(tag,1,"|"), word(tag,2,"|"), word(tag,3,"|"), Scope), fldlist) cResult = evaluate_template(code) END FUNCTION
This function creates the DIM statement for each variable.
FUNCTION GenerateDIMLine as C ( Name as C , ShortType as C, LongType as C, Scope as C ) DIM cResult as C IF LongType = "Memo" ShortType = "C" END IF IF .NOT. inlist(ShortType, "A", "C", "D", "N", "L", "T", "Y") ShortType = "B" END IF cResult = "DIM "+Scope+" ptr." + Name + " as " + ShortType GenerateDIMLine = cResult END FUNCTION
See Also