Using CodeSite logging with Rubicon or WebHub

CodeSite logging is a tremendous advantage. Here is a summary of the common stumbling blocks. If you can remember Setup in Unrestricted mode and Search Path using $(Platform) – you will be well on your way. Details below.

Ray Kanopka is the author of CodeSite and he has published many excellent presentations about it for various Delphi conferences. I highly recommend watching at least one of those to learn the full capabilities.

In any recent Delphi version, you can get CodeSite Express for free from Tools > GetIt. You can buy the full pro version with source directly from Ray’s company, Raize. He does raise the bar for all of us!

When installing any CodeSite edition, the first thing to remember is to go through the Setup screens carefully. There is one screen where the default installation mode is “stealth” and as a developer, you probably want “unrestricted” mode. In stealth mode, you do not get a tray icon for CSDispatcher and things can get very confusing. You would need to use TaskMgr to see whether CSDispatcher.exe is in memory. If that happens to you, install again to fix the mode.

Rubicon core (r_core*.pas) source code intentionally uses CodeSite directly, so that there are no extra dependencies that would cause conflicts when WebHub is also installed. However the Rubicon and WebHub sample projects all use the ZM_CodeSiteInterface.pas unit which wraps many of the CodeSite calls such that the compiler only generates code for them if you have compiled with -DCodeSite on the dcc32 command line, or with CodeSite as a conditional define from the IDE. i.e. you control the overhead to a large extent at compile time.

With direct CodeSite, you might write

// uses CodeSiteLogging;
CodeSite.Send('var1', var1);

With the wrapper, you would might write

//uses ZM_CodeSiteInterface;
CSSend('var1', var1); // where var 1 is a string.

In order to compile with CodeSite Express, you will need the path to the appropriate CodeSiteLogging.dcu on your local disk. This location changes with each major release of Delphi.

Ideally, you want that path to be expressed in a way that it works every way that you compile from the IDE, whether Debug or Release, whether win32 or win64. There is an easy way to accomplish that by using the $(Platform) variable when you specify the path.

For example, this is where my CodeSiteLogging.dcu lives at the moment:

K:\Vendors\Raize\CodeSite5\Lib\RX11$(Platform)

Please note the use of $Platform to mean win32 or win64, whichever platform is selected at compile time.

Your files are probably under C:\Program Files (x86)\Raize but might be on D: if Delphi was installed on D.

Make sure to take the extra few seconds to select ALL platforms, ALL configurations BEFORE you put in the search path. That way you do not need to repeat this work every time you change the compilation target. See the screenshot above, that’s what it looks like in Delphi 11.2 today.

Important: whenever you add or remove a compiler directive, you need to Project > Build to recompile all units, especially ZM_CodeSiteInterface.pas, with the adjusted CodeSite flag. Otherwise, Delphi is quite likely to overoptimize and link in a DCU file which does not include your requested change.

If I missed your issue or you have any questions, please reply…

Ann