DelphiFAQ Home Search:

Clearing a console window screen

 

comments2 comments. Current rating: 5 stars (1 votes). Leave comments and/ or rate it.

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;

Content-type: text/html

Comments:

2007-04-25, 04:57:18
[hidden] from Germany  
rating
Wich units I need for that solution?
2007-07-31, 08:18:05
dineshimed@gmail.com from India  
I have used this function to clear the console screen. But it is not working.
When i am calling this function it just terminating the application.So Please tell me how can i use this function successfully

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: