JavaScript Editor js editor     Web development 

Main Page

Allocates size bytes of space in the memo file for a field and inserts the new block number in the associated record in the database.

long _AllocMemo(Locator FAR *fld, long size)
Locator FAR *fld;            /* Pointer to locator
 that defines the memo field. */
long size;                     /* Size of allocated space in bytes. */


When _AllocMemo( ) is successful, it returns the location in the file to begin writing; otherwise, it returns – 1.

Writing more than size bytes causes memo file corruption.

If you plan to replace a memo field using direct methods, be sure your routine calls _AllocMemo(В ) before writing to the memo file, even if the new value is the same length or smaller than the original. This prevents problems in multiuser situations. _AllocMemo(В ) reuses the previously allocated space when it's safe to do so.

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 creates new memo field contents.

Visual FoxPro Code

В Copy Code
CREATE TABLE wMemo (memoField M)
= NewMemo(@MemoField, "Hello, World.")
= NewMemo(@MemoField, "Isn't this fun?")

C Code

В Copy Code
#include <pro_ext.h>

FAR newMemo(ParamBlk FAR *parm)
   Locator FAR *memoFldLoc;
   FCHAN fchMemo;
   int memoLen;
   long loc;

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

   if ((loc = _AllocMemo(memoFldLoc, memoLen)) == -1)
      _UserError("_AllocMemo() failed");
   _FSeek(fchMemo, loc, FS_FROMBOF);
   _FWrite(fchMemo, _HandToPtr(parm->p[1].val.ev_handle), memoLen);

FoxInfo myFoxInfo[] = {
   {"NEWMEMO", (FPFI) newMemo, 2, "R,C"},
FoxTable _FoxTable = {
   (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo

See Also

JavaScript Editor js editor     Web development