Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-08

Word of warning when sharing code between Delphi and FPC

6 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi Everybody,

I have been battling with some code in tiOPF that causes problems when compiled with Delphi 2007, but not with Delphi 7 and FPC. After some head scratching, we found the problem.

I use {$IFDEF DEBUG} quite often in my code, to hide things like writeln() statemens. I then have a commented DEBUG define at the top of the unit, so I can enable it per unit when required. That's just how I work... ;-)

Anyway in Delphi 2007 there are two compilable states, Release and Debug, with one of those terms automatically added to the options at compile time. Debug mode is the default, which means the DEBUG define is ALWAYS defined - and what caused the problem! writeln() statements fail in a Windows GUI application because StdOut is not available.

Just thought I might share this experience with you guys - to minimize future head scratching. ;-)

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Michael Van Canneyt
to Mattias Gärtner
Mattias G?rtner wrote 23 lines
Zitat von Graeme Geldenhuys : > Hi Everybody, > > I have been battling with some code in tiOPF that causes problems when > compiled with Delphi 2007, but not with Delphi 7 and FPC. > After some head scratching, we found the problem. > > I use {$IFDEF DEBUG} quite often in my code, to hide things like > writeln() statemens. I then have a commented DEBUG define at the top > of the unit, so I can enable it per unit when required. That's just > how I work... ;-) > > Anyway in Delphi 2007 there are two compilable states, Release and > Debug, with one of those terms automatically added to the options at > compile time. Debug mode is the default, which means the DEBUG define > is ALWAYS defined - and what caused the problem! writeln() statements > fail in a Windows GUI application because StdOut is not available. > > Just thought I might share this experience with you guys - to minimize > future head scratching. ;-) Will FPC do the same in Delphi mode?

No. It's an IDE feature. Something like 'named compiler options'. The Delphi compiler by itself doesn't do anything. It just gets the -DDebug and whatever flags from the IDE.

Michael.

Reply by email

Graeme Geldenhuys
to Mattias Gärtner: An embedded and charset-unspecified text was scrubbed... Name: not available Url:…
Mattias G?rtner wrote
Will FPC do the same in Delphi mode?

It's nothing todo with the compiler, it's the IDE that injects '-dDebug' when the project is compiled in Debug mode. I would guess (though not tested), that '-dRelease' is injected when Release mode is used in the IDE.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

mitya boyarintsev
to Graeme Geldenhuys

how about, redirecting writeln's somethere in Delphi Debug mode?

something like that. I'm not sure if it works

initialization
{$ifndef fpc}{$ifdef debug}
AssignFile(output, 'redirstdout.txt'); Rewrite(output);
{$endif}{$endif}
finalization
{$ifndef fpc}{$ifdef debug}
CloseFile(output);

{$endif}{$endif}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20080829/1be80c6d/attachment.html

Reply by email

Graeme Geldenhuys
to mitya boyarintsev

2008/8/29 mitya boyarintsev :

how about, redirecting writeln's somethere in Delphi Debug mode? something like that. I'm not sure if it works

After thinking about it for a while it hit me!! The code I'm working with is from the tiOPF project. It already has a solution via tiLog('...message goes here...', lsDebug) calls. tiOPF allows tiLog() calls to output to Console, GUI or File without issues. lsDebug is one of many log severity levels that can be set. Simply passing in a different parameter to the program, different output methods can be used. I can't believe I never thought of using that from the start - so we learn. :-)

Either way, for those developers not using tiOPF, be warned about the global Debug define in D2007.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email