I have a common unit that does some logging to GExperts Debugger and/or OutputDebugString. I am going to use it in a console app, so I want it to be able to output to stdout via writeln()
.
The main executable has {$APPTYPE CONSOLE} already, but I don't think that'll help me here. The logging routine will be called from several places:
- the main console app, which will link to a BPL,
- from another BPL that "requires" the first bpl, and.....
- from a DLL that statically links the unit.
The BPLs and DLL will be built with no visibility to the {$APPTYPE CONSOLE} directive, so I can't use IFDEF conditional compilation. The BPL and DLL need to be able to go either way, depending whether the main app is a regular winapp or console app.
One ugly solution that occurred to me is to use the name of the executable. ex:
if (UpperCase(ExtractFileName(ParamStr(0))) = 'MYCONSOLEAPP.EXE') then ...
But I hate to do that, as I could have other console apps...
I'd rather just have a magic function AmIAConsoleApp : boolean; Is there anything like that? I'm using Delphi2005 on this project.
Update: I see that I'm kind of a duplicate of this question, but I'd like to survey the Delphi folks to see if there's a better approach.