DelphiFAQ Home Search:

Clearing a console window screen

 

comments11 comments. Current rating: 3 stars (10 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;

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
2020-07-04, 21:19:59
Roland from Ukraine  
rating
buying cialis online legal
2020-07-06, 08:54:23
Sean  
rating
does walmart have generic viagra
2020-07-06, 14:19:23
Alannah  
rating
top male enhancement pills gnc
2020-07-09, 01:52:22
Carlota  
rating
continuous albuterol nebulization children
2020-07-22, 01:45:23
Bobby from Germany  
rating
cialis.com
2020-07-22, 22:02:41
Chasity from United States  
rating
viagra capsule
2020-07-27, 06:13:48
Valorie  
rating
walmart online shopping tylenol
2020-09-16, 11:06:27
John from United States  
rating
over counter antibiotics at walmart
2020-09-20, 00:17:41
Karl from Schonenwerd, Switzerland  
rating
buying generic viagra online

 

 

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: