DelphiFAQ Home Search:
General :: Programming :: Delphi
General Delphi related information.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.
Recommended links on this topic:
Featured Article

Clearing a console window screen

Question:

How do I clear a console screen?

Answer:

Call the function ClearConsoleScreen as shown below.

function ClearConsoleScreen: boolean;
 const
   BUFSIZE = 80*25;
 var
   Han,Dummy: LongWord;
   buf: string;
   coord: TCoord;
 begin
   Result := false;
   Han := GetStdHandle(STD_OUTPUT_HANDLE);
   if Han <> INVALID_HANDLE_VALUE then
   begin
     if SetConsoleTextAttribute(han, FOREGROUND_RED or FOREGROUND_GREEN or FOREGROUND_BLUE) then
     begin
       SetLength(buf,BUFSIZE);
       FillChar(buf, length(buf),' ');
       if WriteConsole(han,PChar(buf),BUFSIZE,Dummy,nil) then
       begin
         coord.X := 0;
         coord.Y := 0;
         if SetConsoleCursorPosition(han,coord) then
           Result := true;
       end;
     end;
   end;
 end;

Generated 8:01:16 on Nov 12, 2019