AM wroteTo me, this seems wrong but I haven't been
able to determine how to name a window so I can just put calls in the code
to MainWindow, TimerWindow, etc. Is there a better way to do this??
Can you encapsulate the window functionality in a class? I am not sure how the window unit works, as I have always done direct screen writes (and the Win32 equivalent). From what little I remember, you don't get a "handle" to the window, per se, so you can't really store it as a named thing. Perhaps this would work...
Type
TTextWindow = Class (TObject)
private
FLeft,
FRight,
FTop,
FBottom : Byte;
FCursorX,
FCursorY : Byte;
procedure SaveWindow;
procedure RestoreWindow;
public
constructor Create(Top, Left, Bottom, Right : Byte); override;
procedure WinWrite(S: String);
procedure WinWriteXY(S: String);
procedure WinClrScrn;
procedure WinGotoXY(X,Y: Byte);
end;
constructor TTextWindow.Create(Top, Left, Bottom, Right : Byte);
Begin
inherited Create;
FTop := Top;
FLeft := Left;
FBottom := Bottom;
FRight := Right;
Window(FTop, FLeft, FBottom, FRight);
SaveWindow;
End;
Procedure TTextWindow.SaveWindow;
Begin
FCursorX := WhereX;
FCursorY := WhereY;
End;
Procedure TTextWindow.RestoreWindow;
Begin
Window(FTop, FLeft, FBottom, FRight);
GotoXY(FCursorX, FCursorY);
End;
procedure TTextWindow.WinWrite(S: String);
Begin
RestoreWindow;
Write(S);
SaveWindow;
End;
procedure TTextWindow.WinWriteln(S: String);
Begin
RestoreWindow;
Writeln(S);
SaveWindow;
End;
procedure TTextWindow.WinClrScrn;
Begin
RestoreWindow;
ClrScrn;
SaveWindow;
End;
procedure TTextWindow.WinGotoXY(X,Y: Byte);
Begin
RestoreWindow;
GotoXY(X,Y);
SaveWindow;
End;
Var
MyFirstWindow, MySecondWindow : TTextWindow;
Begin
MyFirstWindow := TTextWindow.Create(1,1,10,40);
MySecondWindow := TTextWindow.Create(11,1,21,40);
MyFirstWindow.WinWriteln('Hello');
MySecondWindow.WinWriteln('Hello');
MyFirstWindow.WinWriteln('Hello Again');
MySecondWindow.WinWriteln('Hello Again');
MyFirstWindow.Free;
MySecondWindow.Free;
End;
This is totally untested, and obviously you'll want more (like text attributes and so on) but it should be close to what you need. Just remember that you can't overlap windows with this approach (well, you can, but it would be ugly...)
Hope this helps,
Jeff.