There are many scenarios where you do not want certain things to happen when your components is in design-time. These are things which of course should only be performed when the actual product is being run. There's a simple solution to this, but first the background.
The Delphi TComponent is the primary class for any and all components and controls which can be published into the IDE's palette. With that being said, The Delphi language provides ways of doing such checks built-in to the component's base class. Every component has an enumerated set which you can read to detect its current state. This property is called ComponentState.
In System.Classes we find...
Code:
TComponentState = set of (csLoading, csReading, csWriting, csDestroying,
csDesigning, csAncestor, csUpdating, csFixups, csFreeNotification,
csInline, csDesignInstance);
As you can see, this property provides a number of flags to inform you of certain states of your component. One of those is csDesigning. This is the flag you want to check for when identifying if your component is in design-time.
Code:
if not csDesigning in ComponentState then begin
DoSomethingOnlyInRuntime;
end;
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.