Paul
Paul

Reputation: 26640

Project-wide custom component

Can I have a custom visual component (a slightly modified TSpeedButton) that could be dragged to form and exists across some project only, not requiring to be registered Delphi-wide? I also do not want to emulate button using TFrame. It should not be available to other Delphi projects.

Upvotes: 0

Views: 165

Answers (2)

David Heffernan
David Heffernan

Reputation: 612794

You might be able to use what is known as an interposer class. Define your custom component like this:

type
  TSpeedButton = class(Buttons.TSpeedButton)
    ....
  end;

Note that the class name is the same as the parent class. That is required to make the technique of interposing work.

Put your customisations into this interposer class. When you come to build your UI in the designer, use TSpeedButton from the palette. Make sure that the unit which declares your customised component is listed in the uses clause of each form that contains one of the customised components.

At runtime when the form is streamed, your interposed component will be instantiated rather than the original component.

The downside of this is that you cannot arrange for your customisations to be visible at design time. If you need to set properties that are not present in the vanilla component, then they must be done at run time. That is a consequence of your desire not to install anything in the IDE.

If this approach does not meet your needs then you should make a component in the usual fashion, using a design time package. You can arrange that the package is only included in specific projects, if you so wish.

Upvotes: 2

Remy Lebeau
Remy Lebeau

Reputation: 595320

Unfortunately, no. Using the component at design-time requires putting it into a package that is installed into the IDE. However, you can enable/disable installed packages on a per-project basis as needed.

Upvotes: 3

Related Questions