I have a generic block that does some writing to the GExperts Debugger and / or OutputDebugString. I am going to use it in a console application, so I want it to be able to output to stdout via writeln() .
The main executable already has {$ APPTYPE CONSOLE}, but I donโt think it will help me here. The logging procedure will be called from several places:
- The main console application that will reference the BPL
- from another BPL that "requires" the first bpl, and .....
- from a dll that statically links the device.
The BPL and DLL will be built without the visibility of the {$ APPTYPE CONSOLE} directive, so I cannot use IFDEF conditional compilation. The BPL and DLL should be able to go anyway, depending on whether the main application is a regular winapp or console application.
One ugly solution that occurred to me was to use the name of the executable. ex:
if (UpperCase(ExtractFileName(ParamStr(0))) = 'MYCONSOLEAPP.EXE') then ...
But I do not want to do this, as I may have other console applications ...
Most likely, I have the magic function AmIAConsoleApp: boolean; Is there anything similar? I am using Delphi2005 in this project.
Update: I see that Iโm kind of a duplicate of this question , but I would like to interview Delphi people to see if there is a better approach,
source share