SetTextBuf (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example reads a file into a buffer and then dumps the buffer into a new file, WOOF.DOG.

Code

procedure TForm1.Button1Click(Sender: TObject);
var
  F, FTwo: System.TextFile;
  Ch: Char;
  Buf: array[1..4096] of Char;  { 4K buffer }
begin
  if OpenDialog1.Execute then
  begin
    AssignFile(F, OpenDialog1.FileName);
    { Larger buffer for a faster reading }
    System.SetTextBuf(F, Buf);
    Reset(F);
    { Dump text file into another file. }
    AssignFile(FTwo, 'WOOF.DOG');
    Rewrite(FTwo);
    while not Eof(f) do
    begin
      Read(F, Ch);
      Write(FTwo, Ch);
    end;
    System.CloseFile(F);
    System.CloseFile(FTwo);
  end;

Uses