Delphi Clinic C++Builder Gate Training & Consultancy Delphi Notes Weblog Dr.Bob's Webshop
Bob Swart (aka Dr.Bob) - Medical Officer Delphi 6 Developer's Guide
 Dr.Bob's Tip-Of-The-Hat #13
See Also: Delphi Papers, Columns and other Tip-Of-The-Hats

Design or Runtime?
Sometimes it can be useful to know if your code is executing at design-time or at runtime. Although most components work in design mode exactly the way they work in execution mode, there is one way to make your code detect whether or not you're still in design mode or execution mode: the flag csDesigning in the ComponentState property will tell us exactly that. In Delphi and Kylix, this can be coded as follows:

  if csDesigning in ComponentState then
For C++Builder, this would be coded as follows:
  if (ComponentState.Contains(csDesigning))
This small but nice feature will enable us to put a lot of extra (debug) code and information at design places that are no longer used then we generate a true executable. All with the same code!

And now that we're at it: what about determining if your application is running stand-alone or inside the Debugger of Delphi, Kylix or C++Builder? That's also not too hard, using the DebugHook property.

  if DebugHook <> 0 then
    ShowMessage('Debugging from IDE')
Obviously, you can combine the two in order to distinguish between design-time, debug-time and "real" runtime.

This webpage © 2001-2009 by Bob Swart (aka Dr.Bob - All Rights Reserved.