Programming Guide



sm_*getfield

Copies the contents of a field

int sm_getfield(char *buffer, int field_number);
int sm_e_getfield(char *buffer, char *field_name, int element);
int sm_i_getfield(char *buffer, char *field_name, int occurrence);
int sm_n_getfield(char *buffer, char *field_name);
int sm_o_getfield(char *buffer, int field_number, int occurrence);

buffer
On return, contains the data copied from the specified field.

field_name, field_number
The field to copy, where field_name can be the name of a field or group.

element
The element to copy.

occurrence
The occurrence to copy.

Environment

C only

Returns

Description

sm_getfield copies data from the specified field or occurrence to buffer. Panther omits leading blanks from right justified fields and trailing blanks from other fields If you specify the field by name and the field is not on the screen, Panther looks for the corresponding LDB entry. If you call the function during screen entry processing, Panther first checks the LDB for an entry if ENTEXT_OPTION is set to LDB_FIRST.

Make sure that buffer is large enough to receive the field's contents—at least one greater than the field's maximum length.

If you call sm_n_getfield on a radio button group that allows one selection, buffer gets the group occurrence number of the selected item. For example, the radio button group rating has the third occurrence, PG-13, selected:

Given this selection, the following call to sm_n_getfield puts the string "3" into buffer:

retvar = sm_n_getfield(buffer, "rating");

To get selections in a group that allows multiple selections—for example a group of check box widgets—issue successive calls to either sm_i_getfield or sm_o_getfield. For example, the genre check box group has occurrences 1, 3, and 4 selected:

Panther sees a group's value as an array whose elements contain the offsets of the selected items. Thus, Panther stores the selections in genre as follows:

genre[1] = "1"
genre[2] = "3"
genre[3] = "4"
genre[4] = " "

The following code gets the selections in genre through successive calls to sm_i_getfield:

int len, grp_occ, num_occs;
char *select_val;

/* get number of selections in group "genre" */
num_occs = sm_prop_get_int(sm_prop_id("genre"),
PR_NUM_OCCURRENCES);

/* get offset of selections */
for (grp_occ = 1; grp_occ <= num_occs; grp_oc++)
{
len = sm_i_getfield(select_val, "genre", grp_occ);
...
}

Each call to sm_i_getfield gets the next val selection in the group and puts its offset into select_val. For instance, when grp_occ is 2, sm_i_getfield gets the second-selected item in genre and puts its offset value, 3 (Sci-Fi), into select_val.

Example

#include <smdefs.h>

/* Save the contents of the "rank" field in a buffer
* of the proper size. */

int size;
char *save_rank;

size = sm_n_dlength("rank");
if ((save_rank = malloc(size + 1)) == NULL)
report_error("malloc error.");
else
sm_n_getfield(save_rank, "rank");

See Also

sm_dblval, sm_fptr, sm_intval, sm_lngval, sm_putfield