Reputation: 3839
When I open a form, I am suddenly getting an error message:
"Error reading form: 'X' "
Cache is not initialised. Must call TCache.Initialise first. Ignore the Error and continue? NOTE: Ignoring the error may cause components to be deleted or property values lost"
The "Cache is not initialised" bit is an exception raised by one of our classes.
My first question is, why is the Delphi IDE running my code without me asking it to "Run Program"? What code does it run? Is there any way to turn this off?
Secondly, is there any way I can trap this error in the debugger, so I can work out where in the call stack this exception occurs? I have tried putting a breakpoint where the exception is thrown, but Delphi ignores it.
And also, once I have worked out where this exception is coming from, is there a way to tell when I am in "design mode" and not run that code, or run different code? Or even better, not run that code at all if in design mode? [Update: See Francois' answer to how to stop code running in design mode.]
Upvotes: 3
Views: 1024
Reputation: 596041
When the IDE loads a DFM, it creates live objects within the Form Designer, which means component run-time code is actually run within the IDE. As such, component code needs to check the TComponent.ComponentState
property for the csDesigning
flag if it wants to skip running portions of its code at design-time.
Upvotes: 4
Reputation: 21640
You have some component code that you wrote that is executed when the IDE is trying to load the dfm.
You can test in your code if your component is in "design mode" with
if (csDesigning in ComponentState) then
Upvotes: 4