Mirror

Using Console in non-console applications (Views: 100)


Problem/Question/Abstract:

How to implement console input/output for non-console applications?

Answer:

For implementing console input/output for non-console applications you should use the AllocConsole and FreeConsole functions.
Example below demonstrates using these functions:

procedure TForm1.Button1Click(Sender: TObject);
var
  s: string;
begin
  AllocConsole;
  try
    Write('Type here your words and press ENTER: ');
    Readln(s);
    ShowMessage(Format('You typed: "%s"', [s]));
  finally
    FreeConsole;
  end;
end;

<< Back to main page