Installing a User Pointer in a Field or Form

The user pointer is of type long. It can contain a numeric value, or point to any type of variable or structure. Install a user pointer to a data object in a form, data field or memo field with the user pointer set function, userp_set():

userp_set(datap, itemp); 
 
long datap;
/* Pointer to data
*/
PTR itemp;
/* Pointer to item
*/

For example, you can place a pointer to an integer in a data field with:

DFIELDPTR fldp;    /* Pointer to a data field    */

int maxval = 100;

fldp = fld_def(0, 0, NULLP, 0, "999", F_INT, (PTR) &data, dfmp);

userp_set(&maxval, fldp);

You should be sure that the variable pointed to by the user pointer is available for use when you access this value. If the variable pointed to by the user pointer is out of scope, a memory overwrite will occur in your code.


Home Contents Previous Next