user729103
user729103

Reputation: 651

Make/reuse a custom component in delphi with fixed layout properties (design)

Is it possible to create a custom component, not only by adding extra functionality like methods and events, but also design the custom component (so that color, font, ... shouldn't be set when adding that component).

I would like to use this to construct a custom TDBGrid which I reuse and can just add to a form properly designed.

Thanks in advance!

Upvotes: 1

Views: 671

Answers (2)

Maksee
Maksee

Reputation: 2401

Component templates should serve the task. After you're created and installed the component, drop it on the form, adjust every property you want to, go Component-Create Component Template, choose name and palette page. Starting this moment you can select and drop your customized variant on the form

Since the copied component is a simple text inside clipboard, you can also copy-paste your customized component to a text file and when you need this copy, just select this fragment and copy it as a simple text, Delphi form will accept this object when you paste it. You even can organize a little storage for your saved component after the "end." in the module or inside comments, both will be safely bypassed by the compiler.

Upvotes: 0

ain
ain

Reputation: 22749

Everything you can do in the designer you can "code into your component". Generally you just redeclare the new default values for properties and set / initialize them in the overriden constructor. Ie to create custom panel with red color as default you'd do

type
  TMyPanel = class(TPanel)
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Color default clRed;
  end;

constructor TMyPanel.Create(AOwner: TComponent);
begin
  inherited;
  Color := clRed; 
end;

Upvotes: 1

Related Questions