2010. május 12., szerda

Using Console in non-console applications


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;

Nincsenek megjegyzések:

Megjegyzés küldése