We help IT Professionals succeed at work.

Clear Screen in Delphi's Console Application

palare98
palare98 asked
on
Medium Priority
6,552 Views
Last Modified: 2012-05-04
I am in a class learning Pascal.  We are using the Console Application function of Delphi.  In Turbo Pascal there was a built in function for clearing the screen.  It was something like ClrScr.  Is there something like this in Delphi?  I'm not looking for some huge procedure to do this.  I already have one of those.
Comment
Watch Question

Commented:
Delphi doesn't ship with a crt unit, unlike turbo pascal, but you can get a free one here: http://www.mindspring.com/~efd/tools.htm . A description:

"Crt_EFD is a Delphi32 console mode reproduction of the DOS text mode features found in the Crt unit from Turbo Pascal v7.0. Freeware with source code."

GL
Mike

Commented:
hello palare98, there isn't much (that I could find) in delphi to do things whith Console apps except write and read. I had to use windows API console fuctions to do things like change the text and background colors. As for clearing the screen, I never did see if there was an API for clear Screen? ? I clear the screen just by using  WriteLn('');   enough times to get every thing off the screen. Here is the Code I use to do that - - -



program unins;
{$APPTYPE CONSOLE}
uses
  Windows,
  Messages,
  SysUtils;

var
Str1: String;
hStdOut: HWnd;
ScreenBufInfo: TConsoleScreenBufferInfo;
Coord1: TCoord;
i: Integer;

begin
hStdOut := GetStdHandle(STD_OUTPUT_HANDLE);
Writeln('This is a test?');
Writeln('Does it work?');
ReadLn(Str1);
WriteLn('1 Ok we got anoter test line here');
WriteLn('2 Ok we got anoter test line here');
WriteLn('3 Ok we got anoter test line here');
WriteLn('4 Ok we got anoter test line here');
WriteLn('5 Ok we got anoter test line here');
WriteLn('6 Ok we got anoter test line here');
WriteLn('7 Ok we got anoter line here');
WriteLn('8 Ok we got anoter line here');
WriteLn('9 Ok we got anoter line here');
ReadLn(Str1);



// code for Clear Screen
GetConsoleScreenBufferInfo(hStdOut, ScreenBufInfo);
{the GetConsoleScreenBufferInfo API gets the size of
the buffer I need}
for i := 1 to ScreenBufInfo.dwSize.Y do
WriteLn('');
Coord1.X := 0;
Coord1.Y := 0;
SetConsoleCursorPosition(hStdOut, Coord1);
{SetConsoleCursorPosition API sets your cursor
to the Coord1, at 0, 0    the beginging}


ReadLn(Str1);

end.

- - - - - - - - - - - - - - - - - - -
this works for me, but I don't use Console very much.
maybe you have not used any windows API yet. let me know

Author

Commented:
I will try it an let you know.  We have not gotten into API yet.

Commented:
How'd you make out?

GL
Mike

Author

Commented:
I ended up getting what I needed from a dcu that was written by a guy that I know.  I am going to give each of you points though.

Slick, I will write another question for you as soon as I get the chance.

Commented:
Thanks, Glad you were able to get a solution.

GL
Mike