Delphi Clinic | C++Builder Gate | Training & Consultancy | Delphi Notes Weblog | Dr.Bob's Webshop |
|
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 ShowMessage('Design-time') else ShowMessage('Runtime');For C++Builder, this would be coded as follows:
if (ComponentState.Contains(csDesigning)) ShowMessage("Design-time"); else ShowMessage("Runtime");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!
Debugging?
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') else ShowMessage('Standalone')Obviously, you can combine the two in order to distinguish between design-time, debug-time and "real" runtime.