sx_FieldOffset

<< Click to Display Table of Contents >>

Navigation:  Apollo API Listing >

sx_FieldOffset

VB Declaration

Declare Function sx_FieldOffset Lib "Apollo9.dll"

(ByVal cpFieldName As String)

As Integer

C Declaration

USHORT FAR PASCAL sx_FieldOffset

(BYTEP cpFieldName);

Description

Gets offset of named field in record buffer (relative to 1). The first field will always have an offset of 2. The deletion flag offset is 1.

 

Useful if using sx_GetRecord to read the contents of a complete record into a string buffer.

Parameters

cpFieldName: The name of the field.

Return Value

The offset of the named field into the record buffer (relative to 1). If the field name is invalid, zero is returned.

VB Example

Sub LoadData ()

Dim i As Integer

Dim cField As String

 

' extract record

RecString = String$(sx_RecSize(), 0)

Call sx_GetRecord(ByVal RecString)

 

' Load control array

For i = 1 to sx_FieldCount()

cField = sx_FieldName(i)

tBox(i - 1).Text = Mid$(RecString, sx_FieldOffset(cField),

Ä (sx_FieldWidth(cField))

Next i

End Sub

C Example

// fill list box with field names and record data

uiFieldCount = sx_FieldCount();

cpRecord = sx_MemAlloc((LONG) sx_RecSize() + 1);

sx_GetRecord((BYTEP) cpRecord);

// set list box items

for (i = 0; i < (SHORT) uiFieldCount; i++)

{

lstrcpy((LPSTR) caFieldName, (LPSTR) sx_FieldName(i + 1));

lstrcpy((LPSTR) caFieldType, (LPSTR) sx_FieldType(caFieldName));

 

// non-memos only

if (caFieldType[0] != 'M')

{

_fmemset(caString, 0, (size_t) sizeof(caString));

lstrcpy(caString, caFieldName);

caString[lstrlen(caString)] = '\t';

_fstrncpy(caString[lstrlen(caString)],

cpRecord[sx_FieldOffset(caFieldName) - 1],

sx_FieldWidth(caFieldName));

SendDlgItemMessage(hdlg, ID_L1,  

LB_ADDSTRING, NULL, (LPSTR) caString);

}

}

sx_MemDealloc(cpRecord);

See Also

sx_FieldCount, sx_FieldDecimals, sx_FieldName, sx_FieldNum, sx_FieldType, sx_FieldWidth