I am trying to create a spinner / wait cursor in a Delphi console application. I can do it but I am sure the code can be streamlined / improved significantly. Please forgive the poor code:
Procedure PositionXY( x , y : Integer);
var
hStdOut: HWND;
ScreenBufInfo: TConsoleScreenBufferInfo;
Coord1: TCoord;
z: Integer;
Begin
sleep(100);
hStdOut := GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hStdOut, ScreenBufInfo);
Coord1.X := x;
Coord1.Y := y;
SetConsoleCursorPosition(hStdOut, Coord1);
End;
begin
while True do begin
Write('|');
PositionXY(0,0);
Write('/');
PositionXY(0,0);
Write('-');
PositionXY(0,0);
Write('\');
PositionXY(0,0);
end;
ReadLn;
end.
Thanks in advance Paul
This might guide you to some optimizations:
Write('|'#8); Sleep(100);
Write('/'#8); Sleep(100);
Write('-'#8); Sleep(100);
Write('\'#8); Sleep(100);
Hint: The #8 is a BackSpace.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With