Positioning text in the console
There's no built-in way to position the cursor within the Delphi console window, but it's not particularly hard to use the Windows interface to do it.
You'll need to add the Windows unit to the Uses statement.
You'll also need a routine to get a 'handle' to the current console window. This is a pointer which makes sure that the right console window is used.
You'll need to add the Windows unit to the Uses statement.
You'll also need a routine to get a 'handle' to the current console window. This is a pointer which makes sure that the right console window is used.
program helloworld;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,Windows;
var
coords : _COORD;
chandle : THandle;
//-----------------------------------------
// Get handle to console input
//-----------------------------------------
function GetConInputHandle : THandle;
begin
Result := GetStdHandle(STD_INPUT_HANDLE)
end;
//-----------------------------------------
// Get handle to console output
//-----------------------------------------
function GetConOutputHandle : THandle;
begin
Result := GetStdHandle(STD_OUTPUT_HANDLE)
end;
begin
chandle := GetConOutputHandle();
coords.X := 10;
coords.Y := 10;
setconsolecursorposition(chandle,coords);
writeln('This is the army mister jones') ;
readln;
end.
procedure printxy(x,y:integer;s:string);
var
coords : _COORD;
chandle : THandle;
begin
chandle := GetConOutputHandle();
coords.X := x;
coords.Y := y;
setconsolecursorposition(chandle,coords);
writeln(s);
end;