Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



Share:
Notifications
Clear all

[Solved] Lazarus - MacOS X - Writeln debug output for GUI Applications

2 Posts
1 Users
0 Reactions
3,193 Views
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter  

I develop (or pretend to develop) GUI applications, typically on my Mac with Lazarus Pascal.
If possible, I recompile the application under Windows and/or Linux.

One thing that has been annoying me it the lack (of knowledge on my end) of a simple way to output little debug text lines, so I can track certain things easier when debugging my application.

I've seen quite a lot of methods, but found (after some playing) that this works best for me:

1. Open a Terminal window and type:

tty

Which will show something like this:

/dev/ttys000

2. In Lazarus go to "Tools" - "Options" - "Debugger" - "General" and enter this value (/dev/ttys000) in the "ConsoleTty" field.

Now every "Write" and "WriteLn" output will be displayed in this terminal window.
If you do not have a terminal window open, the write(ln) statements will silently fail.

Note : The Terminal window MUST be OPEN before you run you application from the IDE, in order to see any messages.

Tip : It's not a bad idea to use compiler directives to enable/disable these writeln statements:

{$DEFINE DebugToConsole}
...
{$IFDEF DebugToConsole} Writeln('Debug informatie'); {$ENDIF}

You disable {$DEFINE DebugToConsole} by commenting them out:

// {$DEFINE DebugToConsole} 

   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter  

You could of course define a procedure to keep typing to a minimum, right after the "implementation" keyword:

{$DEFINE DebugToConsole}
procedure debug(txt:string);
begin
  {$IFDEF DebugToConsole}
  Writeln(txt);
  {$ENDIF}
end;            

And call all your debug messages like so:

debug('debug message');

   
ReplyQuote
Share: