Reputation: 20211
When writing a Lazarus program, you have the option of using $APPTYPE console
or deselecting the Win32 GUI Application
(-WG
option) in the Project Options .
I noticed that without these options DebugLn
and WriteLn
raise exceptions. Is there a way to create a console even if the program is not compiled above mentioned options and output to it with DebugLn
and WriteLn
afterwards?
Upvotes: 3
Views: 5457
Reputation: 1726
Well, obviously setting project as gui application rather then program is much better for programming. All needed uses clauses are alredy present.
So that kind of problem, getting power of lazarus, but working as console application I solve with adding
Application.ShowMainForm:=False;
before
Application.CreateForm(TForm1, Form1);
in .lpr file.
Everything works fine, even showmessage (everything) can be used.
Upvotes: 2
Reputation: 1593
In windows it is a little more tricky compared to Delphi. In Delphi all you need to do is to call AllocConsole
. Using Lazarus/FreePascal you need to do a little extra work:
uses
Windows;
begin
AllocConsole; // in Windows unit
IsConsole := True; // in System unit
SysInitStdIO; // in System unit
// Now you can do Writeln, DebugLn, ...
end.
Unfortunately I cannot help you on other platforms. Although iirc in linux console is always present for a program even if not visible. So it should work without extra code. However I cannot test this atm so take it with a grain of salt.
Upvotes: 9