Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to keep certain code from executing when my component is in design-time?

Component Writing

How to keep certain code from executing when my component is in design-time?

by  djjd47130  Posted    (Edited  )
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;



Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top