Partager via


_EdGetLineNum( ) API Library Routine

Returns the line number of the passed offset position thePos in the file in the specified editing window.

EDLINE _EdGetLineNum(WHANDLE wh, EDPOS thePos)
WHANDLE wh;            /* Handle of editing window. */
EDPOS thePos;               /* Offset position in the file. */

Example

The following example opens an editing session for a file specified by a parameter and gets the EDPOS for line 12 by calling _EdGetLinePos( ). It then calls _EdGetLineNum( ) on this EDPOS, and this returns 12. Next, it increments the EDPOS and each time calls _EdGetLineNum( ) until the returned EDLINE changes. At this point, it calls _EdGetLinePos( ) for line 13.

Visual FoxPro Code

SET LIBRARY TO EDGETLIN
= EDGETLPOS("x")

C Code

#include <pro_ext.h>

void putLong(unsigned long n)
{
   Value val;

   val.ev_type = 'I';
   val.ev_long = n;
   val.ev_width = 6;

   _PutValue(&val);
}

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

   WHANDLE wh;
   EDENV EdEnv;
   EDPOS edpos;
   EDLINE edlin, original;

   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_READONLY);
   _HUnLock(parm->p[0].val.ev_handle);

   edpos = _EdGetLinePos(wh, 12);
   _PutStr("\n_EdGetLinePos(wh, 12) =");
   putLong(edpos);

   original = edlin = _EdGetLineNum(wh, edpos);

   for (;;)
   {
      _PutStr("\n_EdGetLineNum(wh,");
      putLong(edpos);
      _PutStr(") = ");
      putLong(edlin);

      if (edlin != original)
      {
         break;
      }
      edpos++;
      edlin = _EdGetLineNum(wh, edpos);
   }

   edpos = _EdGetLinePos(wh, 13);
   _PutStr("\n_EdGetLinePos(wh, 13) ="); putLong(edpos);
}

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

See Also

Reference

_EdGetChar( ) API Library Routine

_EdGetLinePos( ) API Library Routine

_EdGetEnv( ) API Library Routine

Other Resources

API Library Construction