Board index » delphi » OutText produces bad output on screen?

OutText produces bad output on screen?

Maybe somebody can see what the problem is,
I have simplified the following routine, it uses
Gettime to get the current Time Seconds then
it goes into a loop where it checks if the
Seconds have changed then repeatedly calls
Gettime again to update the Seconds.
When they change OutTextXY is suppost to
update the Screen output.
The Program is suppost to display a rundown
of the Seconds on screen, however the OutTextXY
Routine starts to produce a corrupted output soon
after the program runs.
I tried Moveto and OutText with the same result,
is there a problem using OutText in a tight loop?
Maybe somebody can see what is wrong here.
I am using Turbo Pascal 7.0
Thanks.

uses Crt, Dos, Graph;

var
 grDriver, grMode :Integer;
 Hour, Minute, Second, Sec100, OldSecond :Word;
 Time :string;

begin
 grDriver := Detect;
 InitGraph(grDriver, grMode,' ');
 if GraphResult <> grOk then begin
    Writeln ('Problem initiating the Graphics driver.');
    Halt(1);
 end;
 GetTime( Hour, Minute, Second, Sec100);
 OldSecond := Second;
 repeat
   if OldSecond <> Second then begin
     Str( Second:0, Time);
     OutTextXY( 10, 10, Time);
     OldSecond := Second;
   end;
   GetTime( Hour, Minute, Second, Sec100);
 until keypressed;
 CloseGraph;
end.

--
Torsten

 

Re:OutText produces bad output on screen?


torsten wrote in <OG7q8.2883$tW2.1...@nwrddc04.gnilink.net>

[deleted]

Quote
> Maybe somebody can see what is wrong here.
> I am using Turbo Pascal 7.0

  You are to drawing old <Second>-value with background color. Or uses
Crt.GotoXY() and System.Write() :-P
  As example:

uses Crt, Dos, Graph;

var
 grDriver, grMode :Integer;
 Hour, Minute, Second, Sec100, OldSecond :Word;
 Time :string;

begin
 grDriver := Detect;
 InitGraph(grDriver, grMode,'bp\bgi');
 if GraphResult <> grOk then begin
    Writeln ('Problem initiating the Graphics driver.');
    Halt(1);
 end;
 GetTime( Hour, Minute, Second, Sec100);
 OldSecond := Second;
 {*}  Str( Second:0, Time);
 repeat
   if OldSecond <> Second then begin
 {*}    SetColor(0);
 {*}    OutTextXY( 10, 10, Time);
 {*}    SetColor(15);
     Str( Second:0, Time);
     OutTextXY( 10, 10, Time);
     OldSecond := Second;
   end;
   GetTime( Hour, Minute, Second, Sec100);
 until keypressed;
 CloseGraph;
end.

--
   Varjonov Konstantin       varkos^mail.ru      http://ghsrl.newmail.ru

Re:OutText produces bad output on screen?


Thanks a lot, your fix works great.
I have to keep in mind that text in graphics dose not do backgrounds.
This will help me on some of my other projects too.

"Konstantin V. Varjonov" <var...@ktk.ru> wrote in message
news:01c1da04$1d8ba560$LocalHost@varkos...

Quote
> torsten wrote in <OG7q8.2883$tW2.1...@nwrddc04.gnilink.net>

> [deleted]
> > Maybe somebody can see what is wrong here.
> > I am using Turbo Pascal 7.0

>   You are to drawing old <Second>-value with background color. Or uses
> Crt.GotoXY() and System.Write() :-P
>   As example:

> uses Crt, Dos, Graph;

> var
>  grDriver, grMode :Integer;
>  Hour, Minute, Second, Sec100, OldSecond :Word;
>  Time :string;

> begin
>  grDriver := Detect;
>  InitGraph(grDriver, grMode,'bp\bgi');
>  if GraphResult <> grOk then begin
>     Writeln ('Problem initiating the Graphics driver.');
>     Halt(1);
>  end;
>  GetTime( Hour, Minute, Second, Sec100);
>  OldSecond := Second;
>  {*}  Str( Second:0, Time);
>  repeat
>    if OldSecond <> Second then begin
>  {*}    SetColor(0);
>  {*}    OutTextXY( 10, 10, Time);
>  {*}    SetColor(15);
>      Str( Second:0, Time);
>      OutTextXY( 10, 10, Time);
>      OldSecond := Second;
>    end;
>    GetTime( Hour, Minute, Second, Sec100);
>  until keypressed;
>  CloseGraph;
> end.

> --
>    Varjonov Konstantin       varkos^mail.ru      http://ghsrl.newmail.ru

Re:OutText produces bad output on screen?


"torsten" <tors...@gte.net> schreef in bericht
news:OG7q8.2883$tW2.1462@nwrddc04.gnilink.net...

Quote
> Maybe somebody can see what the problem is,
> I have simplified the following routine, it uses
> Gettime to get the current Time Seconds then
> it goes into a loop where it checks if the
> Seconds have changed then repeatedly calls
> Gettime again to update the Seconds.
> When they change OutTextXY is suppost to
> update the Screen output.
> The Program is suppost to display a rundown
> of the Seconds on screen, however the OutTextXY
> Routine starts to produce a corrupted output soon
> after the program runs.
> I tried Moveto and OutText with the same result,
> is there a problem using OutText in a tight loop?
> Maybe somebody can see what is wrong here.
> I am using Turbo Pascal 7.0
> Thanks.

> uses Crt, Dos, Graph;

> var
>  grDriver, grMode :Integer;
>  Hour, Minute, Second, Sec100, OldSecond :Word;
>  Time :string;

> begin
>  grDriver := Detect;
>  InitGraph(grDriver, grMode,' ');
>  if GraphResult <> grOk then begin
>     Writeln ('Problem initiating the Graphics driver.');
>     Halt(1);
>  end;
>  GetTime( Hour, Minute, Second, Sec100);
>  OldSecond := Second;
>  repeat
>    if OldSecond <> Second then begin
>      Str( Second:0, Time);
>      OutTextXY( 10, 10, Time);
>      OldSecond := Second;
>    end;
>    GetTime( Hour, Minute, Second, Sec100);
>  until keypressed;
>  CloseGraph;
> end.

> --
> Torsten

phew, that was a hard nut to crack. Crazy.
You have found a bug indeed.
You can demonstrate this by putting
Quote
>      OutTextXY( second, second ,'It is now '+ Time);

On my machine it only shows 'It is now ' and a '0' if the second contains
a 0.

The problem is that you are using the default font, and the standard
BP/TP drivers. In order to display the default font, B/TP searches in the
machine ROM somewhere. Either Windows or the graphic card should have put
the default font definition at the default location. On my machine it did
not so for the numbers 1..9.

A solution is to use drivers where this bug has been fixed, e.g.
www.ryledesign.com
They also have an overwriting mode available so you dont have to remove
the text on the screen any more before you outtext the new value.
Unfortunately these are not for free.

A work-around for the problem is to use one of the stroked fonts. These
are defined by the .CHR files. Place them in the working directory, or
put the correct bgi path in the initgraph statement.
e.g.

uses Crt, Dos, Graph;

var
 grDriver, grMode :Integer;
 Hour, Minute, Second, Sec100, OldSecond :Word;
 time:string;

begin
 grDriver := Detect;
 InitGraph(grDriver, grMode,'c:\bp\bgi');
 if GraphResult <> grOk then begin
    Writeln ('Problem initiating the Graphics driver.');
    Halt(1);
 end;
 GetTime( Hour, Minute, Second, Sec100);
 OldSecond := Second;
 settextstyle(smallfont, HorizDir, 4);
 repeat
   if OldSecond <> Second then
   begin
     setcolor(black);
     OutTextXY( 10, 10, time);   {remove the old time}
     Str( Second, time);
     setcolor(white);
     OutTextXY( 10, 10, +time);
     OldSecond := Second;
   end;
   GetTime( Hour, Minute, Second, Sec100);
 until keypressed;
 CloseGraph;
end.

--
Femme

Other Threads