FRemoveNBytes Function

Action

Removes data at the current position of the file pointer.

Include file

Kernel.bdh

Syntax

FRemoveNBytes( in  hFile    : number,
               in  nBytes   : number,
               out nRemoved : number optional): 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.
nBytes

Number of bytes to remove. If this parameter contains a negative value, all characters between the current file position and the end of the file are removed.

After the function call this parameter contains the number of bytes actually removed.

nRemoved Variable receiving the actual number bytes removed from the file (optional)

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 beautiful world!";
    FWrite(hFile, sOutput);
    write("new file created"); writeln;

    // remove word "beautiful"
    FCurrentPositionSet(hFile, 6, OPT_FILE_BEGIN);
    FRemoveNBytes(hFile, 10);
    write("word 'beautiful' removed"); writeln;

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

Output

new file created
word 'beautiful' removed
file closed