About the author
Where we hang out, Hallvard has mentioned that C# supports Conditional Methods and asked if Delphi supports the same, after reading the Conditional Method article by Eric Gunnerson.
Well, of course!
function DoSomethingOnlyDuringDebug: Boolean;begin Result := True; // Do something here that happens only when in Debug mode such as OutputDebugString('Whee! This message appears only in Debug mode...');end;
....Assert(DoSomethingOnlyDuringDebug);...
Once you're ready to go into production mode, just turn off assertions with {$ASSERTIONS OFF}.
How does that work? By surrounding the call to DoSomethingOnlyDuringDebug with Assert, I have ensured that when {$ASSERTIONS ON} or {$C+} is specified, DoSomethingOnlyDuringDebug is called. Since during production, {$ASSERTIONS OFF} or {$C-}, therefore, DoSomethingOnlyDuringDebug won't be called. Since it won't be called, Delphi's smart linker would strip out the code for DoSomethingOnlyDuringDebug in the final production executable.
Of course, if you're concerned that developers would forget to call DoSomethingOnlyDuringDebug with Assert, you can either use {$MESSAGE WARN 'This routine is only to be called with Assert(RoutineName);'} or note it in some documentation somewhere. In addition, you can walk the code tree from within the routine, and ensure that there is a call to Assert after the call to DoSomethingOnlyDuringDebug. Of course, that would be a much dirtier and messier hack than just a simple documentation, but it would ensure your developers do not forget to call DoSomethingOnlyDuringDebug with Assert.
Did you miss that, Hallvard? Or are you looking for something even simpler? ;o)
Learn why the map is cool in Go!
A method to design records so that they're allocated on a specific byte boundary, such as 16 bytes, 512 bytes, 4096 bytes, etc.
Learn the command line used to compile System.pas in Delphi
How to free more space on your home drive by redirecting the location for SDKs in RAD Studio