_FindMemo( ) API Library Routine

Visual Studio .NET 2003

Returns the memory address of the first character in the memo field fld for the current record in the selected work area.

long _FindMemo(Locator FAR *fld)
Locator FAR *fld;            /* Memo field name. */


_FindMemo( ) enables you to directly gain access to memo field contents for the current record. When the memo field for the current record is empty, or when fld is not the name of a memo field, _FindMemo( ) returns a negative integer whose absolute value is a Visual FoxPro error number.

For more information on how to create an API library and integrate it with Visual FoxPro, see Accessing the Visual FoxPro API.


The following example retrieves the contents of a memo field for the current record. It uses FindMemo( ) to find the location of the memo contents for the current record within the memo file. The example then moves the file pointer to this location with _FSeek( ), and stores the memo field contents in memory using _FRead( _MemoSize( )).

Visual FoxPro Code

CREATE TABLE WMemo (MemoField M)
REPLACE MemoField WITH "Hello, World."
? GETMEMO(@MemoField)

C Code

#include <pro_ext.h>

FAR FindMemoEx(ParamBlk FAR *parm)

   Locator FAR *memoFldLoc;
   FCHAN fchMemo;
   char FAR *memoContents;
   int memoLen;
   long loc;

   if ((fchMemo = _MemoChan(-1)) == -1)
      _UserError("_MemoChan() failed");
   memoFldLoc = &parm->p[0].loc;

   if ((loc = _FindMemo(memoFldLoc)) < 0)
      _UserError("_FindMemo() failed");
   if ((memoLen = _MemoSize(memoFldLoc)) < 0)
      _UserError("_MemoSize() failed");
   if ((memoContents = _Alloca(memoLen + 1)) == 0)
      _Error(182); // "Insufficient memory"
   _FSeek(fchMemo, loc, FS_FROMBOF);
   _FRead(fchMemo, memoContents, memoLen);
   memoContents[memoLen] = '\0';

FoxInfo myFoxInfo[] = {
   {"GETMEMO", (FPFI) FindMemoEx, 1, "R"},
FoxTable _FoxTable = {
   (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo

See Also

_AllocMemo( ) API Library Routine | _DBReplace( ) API Library Routine | _MemoChan( ) API Library Routine | _MemoSize( ) API Library Routine