FCurrentPositionSet Function

Action

Moves the file pointer of an open file by a specified number of bytes from the start of the file or from the current position (thereby setting it to a given position), or moves the file pointer to the end of the file.

Include file

Kernel.bdh

Syntax

FCurrentPositionSet( in hFile       : number,
                     in nShift      : number,
                     in nMoveMethod : number ) : boolean;

Return value

  • true if successful

  • false otherwise

Parameter Description
hFile Valid handle to an open file. This handle must have been returned from a previous call to FOpen.
nShift Number of bytes to shift the file position
nMoveMethod Specifies the start position of the move operation. Possible values are:
  • OPT_FILE_BEGIN. Beginning of the file

  • OPT_FILE_CURRENT. Current file position

  • OPT_FILE_END. End of the file

Example

dcltrans
  transaction TMain
  var
    hFile : number;
    sOutput : string;
  begin
    // create new file and write string to file
    FOpen(hFile, "c:\\temp\\dummyfile.txt", OPT_FILE_ACCESS_READWRITE, OPT_FILE_CREATE);
    sOutput := "Hello world!";
    FWrite(hFile, sOutput);
    write("new file created"); writeln;
     
    // set file position to end of word "Hello"
    FCurrentPositionSet(hFile, 5, OPT_FILE_BEGIN);
    write("current position set to 5"); writeln;

    // set EOF to current position
    FEOFSet(hFile);
    write("EOF set, file contains only the word 'Hello'"); writeln;

    // close file
    FClose(hFile);
    write("file closed"); writeln;

  end TMain;

Output

new file created
current position set to 5 
EOF set, file contains only the word 'Hello'
file closed