sx_Replace

<< Click to Display Table of Contents >>

Navigation:  Apollo API Listing >

sx_Replace

VB Declaration

Declare Sub sx_Replace Lib "Apollo9.dll"

(ByVal cpFieldName AS String,

ByVal iDataType As Integer,

vpData As Any)

C Declaration

VOID FAR PASCAL sx_Replace

(BYTEP cpFieldName,

SHORT iDataType,

VOIDP vpData);

Description

Replace the named field's contents in the record buffer with the given data value.

 

Note that pointers to blobs must be written with sx_PutBlob.

Parameters

cpFieldName: The name of the field.

iDataType: The type of data represented by vpData. It must be one of the following defined constants:

R_INTEGER Short Integer

R_LONG Long Integer

R_DOUBLE Doubles or Floats

R_JULIAN Julian Dates (*)

R_LOGICAL Boolean (T/F)

R_CHAR Character (0-255 bytes long)

R_DATESTR Date String

R_MEMO Memo text

R_BITMAP Bitmap image

R_BLOBFILE Binary Disk File

 

(*) Only JULIAN dates equal or greater than January 1, 1000 are supported.

vpData: vpData must be of the data type indicated by iDataType.

Note that logical fields are replaced by numeric values (0 for False and non-zero for True). The RDE takes care of translating these into "T" or "F" in the case of DBF files.

Replacement values of type R_DATESTR must be formatted according to the setting of sx_SetDateFormat and sx_SetCentury.

Replaced data is not immediately written to disk (except in the case of memos). In a multi user environment it is good practice to physically commit the record changes to disk by calling sx_Commit.

Visual Basic data that is extracted from form text boxes is of type variant. Replacement data of type R_CHAR must be explicitly declared as a string, either by equating the data to a string variable or by using a string operator or function to "cast" the item as a string.

Use the Visual Basic CCur -> CVar conversion functions to convert variants contained in form elements to the appropriate data type.

This is illegal:

sx_Replace "name", R_CHAR, ByVal (Boxname.Text)

It can be corrected by using a VB string function to 'cast' the box text to a string:

sx_Replace "name", R_CHAR, ByVal CStr((BoxName.Text))

Bitmaps and Blobs

Binary large objects (BLOBS) may be stored in memo fields. The maximum size of a binary large object that may be stored with sx_Replace is 16MB.

Bitmaps

A bitmap (i.e., picture) is a type of BLOB; we make the distinction because a BLOB that is explicitly defined as a bitmap may be moved to the Windows clipboard using Apollo functions.

The vpData parameter for R_BITMAP types is passed as a file name (including path) to a standard Windows .BMP or .RLE file. The data is stored in a special format within FPT, SMT, and DBT memo files. If RLE files are stored, they must be run length encoded compressed variants of BMPs in either 4 or 8 bit per pixel format. sx_FieldType returns type "P" for stored bitmaps.

The name of the file is passed in vpData with the ByVal keyword.

sx_Replace "memofield", R_BITMAP, ByVal "c:\path\picture.bmp"

Blobs

Memo fields may store any type of binary data. R_BLOBFILE types refer to any binary large object that is stored in a file. If the type is R_BLOBFILE, the binary object is retrieved from the named file.

BLOB data created by the applications program may also be stored (e.g. numeric arrays). In this case, use sx_PutBlob to write the BLOB to the memo file.

BLOBS may be retrieved with the sx_GetBlob function. Because a BLOB may store any type of information, it is entirely up to the applications programmer as to what is done with the BLOB after retrieval.

 

sx_FieldType returns type "B" for stored BLOBS.

VB Example

' In the replace command for a string that

' resides in a text box, note the use of

' a VB string function (RTrim$) to convert

' the control text to a string from a

' variant. Also note the ByVal applied

' to the string.

' ----------------------------------------

If sx_Rlock(sx_RecNo()) Then

sx_Replace "name", R_CHAR, ByVal RTrim$((BoxName.Text))

sx_Replace "notes", R_MEMO, ByVal CStr((BoxMemo.Text))

sx_Replace "call_time", R_INTEGER, 850

sx_Replace "date", R_JULIAN, 2449293

sx_Replace "elapsed", R_LONG, LongTest&

sx_Replace "time_on", R_DOUBLE, DoubTest#

sx_Replace "status", R_LOGICAL, 0

sx_Commit

sx_Unlock sx_RecNo()

Else

MsgBox "Record lock failed"

End If

C Example

if (sx_Rlock(sx_RecNo())

{

sx_Replace("name", R_CHAR, (VOIDP) cpName);

sx_Replace("call_time", R_INTEGER, (VOIDP) &iCallTime);

sx_Replace("date", R_JULIAN, (VOIDP) &lJulian);

sx_Replace("elapsed", R_LONG, (VOIDP) &lLongTest);

sx_Replace("time_on", R_DOUBLE, (VOIDP) &dDoubTest);

sx_Replace("status", R_LOGICAL, (VOIDP) &bValue);

sx_Replace("memo", R_MEMO, (VOIDP) cpMemoString);

sx_Replace("pict", R_BITMAP, (VOIDP) cpBitmapName);

sx_Commit();

sx_Unlock(sx_RecNo());

}

else

AfxMessageBox((LPCSTR) "Record lock failed");

See Also

sx_AppendBlank, sx_PutRecord, sx_SetDateFormat