Programming Guide |
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.
C only
- 0 The total length of the field's contents.
sm_getfield
copies data from the specified field or occurrence tobuffer
. 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 toLDB_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 grouprating
has the third occurrence,PG-13
, selected:
Given this selection, the following call to
sm_n_getfield
puts the string"3
" intobuffer
: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
orsm_o_getfield
. For example, thegenre
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 tosm_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 nextval
selection in the group and puts its offset intoselect_val
. For instance, whengrp_occ
is 2,sm_i_getfield
gets the second-selected item ingenre
and puts its offset value, 3 (Sci-Fi
), intoselect_val
.
#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");
sm_dblval, sm_fptr, sm_intval, sm_lngval, sm_putfield