Board index » delphi » Copying the contents of a wincrt window to file

Copying the contents of a wincrt window to file

I would like to write a simple program to copy the contents of the wincrt
window to a file.  Why doesn't the following program work?

Program CrtToText;

uses wincrt;

var

  crtfile: Text;
  txtfile: Text;
  charbuffer: char;

begin

  AssignCrt(crtfile);
  Rewrite(crtfile);

  Writeln('This is a test.');
  Reset(crtfile);

  Assign(txtfile, 'M:\BP\SAMPLE\CRTTEST.TXT');
  Rewrite(txtfile);

 while not eof(crtfile) do
   begin

    while not eoln(crtfile) do
    begin {inner loop}
     read(crtfile, charbuffer);
     write(txtfile, charbuffer);
    end; {inner loop}

    readln(crtfile);
    writeln(txtfile);

   end;

  Close(crtfile);Close(txtfile);

end.

 

Re:Copying the contents of a wincrt window to file


Quote
Paul Sun wrote:
> I would like to write a simple program to copy the contents of the wincrt
> window to a file.  Why doesn't the following program work?

As far as I know, the characters you see in a Wincrt window are stored
in a buffer.

This buffer, 'ScreenBuffer:PChar' is in the Implementation section of
the Wincrt unit so you will either have to move it to the interface
section or add your own procedure in the implementation section.

I do not know the limits of writeln and pchars but I would think
something like the following would work to quickly dump the entire
screen to a file...

{untested and untried, add to the Implementation section of Wincrt}
procedure savescreen(filename:string); {I know it is not indented well!}
var f:file;
begin
 assign(f,filename);
 rewrite(f,1);
 blockwrite(f,screenbuffer^,ScreenSize.X*ScreenSize.Y);
 close(f);
end;

--
http://www.geocities.com/aibrain/        "AIBrain Home Page"

"To gain an intimate knowledge of our weapons of destruction,
please place both hands over your eyes and count to three..." -SC2

Other Threads