Share via


_EdSave( ) API Library Routine

_EdSave( ) saves the file in the specified window without ending the editing session.

void _EdSave(WHANDLE wh)
WHANDLE wh;            /* Handle of editing window. */

Example

The following example opens for editing a file specified by a parameter. The example inserts a new line, indents two lines, and deletes two lines. After the insertion of the new line, the example calls _EdSave( ). Then, after the indentation and deletion, the example calls _EdUndo( ) three times in an attempt to undo all of the editing, but the insertion made before the call to _EdSave( ) can't be undone. The example performs two more editing operations, inserting two lines and deleting two lines, with a call to _EdSave( ) between them. Last, the example calls _EdRevert( ), but it too can only undo changes made since the last _EdSave( ).

Visual FoxPro Code

SET LIBRARY TO EDSAVE  
= EDSAVE("x")

C Code

#include <pro_ext.h>

FAR Example(ParamBlk FAR *parm)
{
#define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle))

   WHANDLE wh;

   if (!_SetHandSize(parm->p[0].val.ev_handle, 
      parm->p[0].val.ev_length+1))
   {
      _Error(182); // "Insufficient memory"
   }
   pFILENAME[parm->p[0].val.ev_length] = '\0';

   _HLock(parm->p[0].val.ev_handle);
   wh = _EdOpenFile(pFILENAME, FO_READWRITE);
   _HUnLock(parm->p[0].val.ev_handle);

   _EdSetPos(wh, _EdGetLinePos(wh, 13));
   _EdInsert(wh, "Hello, world\r\n", _StrLen("Hello, world\n"));

   _EdSave(wh);

   _EdSelect(wh, _EdGetLinePos(wh, 14), _EdGetLinePos(wh, 16));
   _EdIndent(wh, 1);

   _EdSelect(wh, _EdGetLinePos(wh, 9), _EdGetLinePos(wh, 12));
   _EdDelete(wh);

   _Execute("WAIT WINDOW 'Press any key to undo changes.'");
   _EdUndo(wh);  // undo deletion
   _EdUndo(wh);  // undo indent
   _EdUndo(wh);  // attempt to undo insertion, but can't

   _EdSelect(wh, _EdGetLinePos(wh, 14), _EdGetLinePos(wh, 16));
   _EdIndent(wh, 1);

   _EdSave(wh);

   _EdSelect(wh, _EdGetLinePos(wh, 9), _EdGetLinePos(wh, 12));
   _EdDelete(wh);

   _EdRevert(wh);   // undoes deletion
}

FoxInfo myFoxInfo[] = {
   {"EDSAVE", (FPFI) Example, 1, "C"},
};
FoxTable _FoxTable = {
   (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};

See Also

_EdCloseFile( ) API Library Routine | _EdOpenFile( ) API Library Routine | _EdRevert( ) API Library Routine | _EdUndo( ) API Library Routine