Newbie Question: Create a component using other components

I have spent countless hours trying to learn how to create a new component, and am coming up short.  I'm sure this question is easy for the experts, but I'm getting frustrated with the lack of answers out there.

I have found several tutorials on creating new components. Many of them mention my problem but never get into details.

I'm creating a component that is a TPanel.  Within that Panel there is a edit box and a label.  I would like to present to the object inspector only certain properties of the panel, and selected properties of the edit and the label.

I have figured out that if you want to "hide" some of the parameters, then you have to use a "TCustomPanel" and only publish the properties of the panel that I want (however, some of them like top/left/help still remain!?!?).  However, I can't for the life of me figure out how to publish the properties of the edit box or the label as properties of the new component.

Ideally, what I would like to do is call the component "MyComponent".  Within the object inspector, I would like to see:

"Heading" (string referring to "label.caption")
"Data" (string referring to "editbox.text")

I figured out that when I publish the properties, I can pass the entire object as a property, and I can see it as a sub item in object inspector.  When I change the value of it in the object inspector, I can see the values updated in the form, HOWEVER when I run the program, the values are reset to the defaults (only on the sub components!)


  TDataField = class (TCustomPanel)
    fHeading: TLabel;
    fData: TEditBox;

    fDataType: String;
    fDigits: Integer;
    fDecimals: Integer;
    fExpression: String;

    constructor Create(AOwner:TComponent); override;
    property Caption;
    property Heading: TLabel read fLabel write fLabel;
    property Data: TEditBox read fData write fData;
    property DataType: String read fDataType write fDataType;
    property Digits: Integer read fDigits write fDigits default 0;
    property Decimals: Integer read fDecimals write fDecimals default 2;
    property Expression: String read fExpression write fExpression;

I create my Label/Editbox in the constructor and give them the default values, but it doesn't appear at runtime the program is passing in the values from the object inspector....but this is only the case with the label/editbox.  Values on the object inspector are correctly applied to the parent panel.

There may be something wrong with my constructor statement.

Anyways, any help would be appreciated!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hello  ncnmra, , I would not want to have a control on my component and then try an Expose it as that control, as you did -

property Data: TEditBox read fData write fData;

although there may be a rare occation that this was nessary, I can not see it,
I would not expose any properties of the Control and just have my own Component properties to adjust that control , , ,

not sure if this is what you are asking, but here is a panel component, that may help you to look at -

unit vPanel;
  SysUtils, Windows, Messages, Classes, stdctrls, Graphics, Controls,
  Forms, ExtCtrls;

  TvPanel = class(TCustomPanel)
    //property Width;
    //property Height;
    FHeading, FData: String;
    FEdit1: TEdit;
    FLabel1: TLabel;
    procedure setHeading(Value: String);
    procedure setData(Value: String);
    property Width;  
// if you move the base component properties into the protected or private, it will hide them from user in form code
    property Height;
    property Caption;
     constructor Create(AOwner: TComponent); override;
    property Heading: String read FHeading write setHeading;
// use a setHeading procedure to access the Control's properties
    property Data: String read FData write setData;


procedure Register;


constructor TvPanel.Create( AOwner: TComponent );
inherited Create(AOwner);
Width := 237;
Height := 71;
ControlStyle:= ControlStyle - [csSetCaption];
FLabel1 := TLabel.Create(Self);
with FLabel1 do
  Parent := Self;
  Color := $84007B;
  Caption := ' vPanel ';
  Font.Style := Font.Style+[fsBold];
  Font.Color := $E8FFEF;
  AutoSize := True;

FEdit1 := TEdit.Create(Self);
with FEdit1 do
  Parent := Self;
  Text := 'No data';
  Font.Name := 'Arial';
Caption := '';

procedure TvPanel.setHeading(Value: String);
widthT: Integer;
oFont: TFont;
if Value <> FHeading then
  FHeading := Value;
  oFont := Canvas.Font;
  Canvas.Font := FLabel1.Font;
  widthT := Canvas.TextWidth(' '+FHeading+' ');
  Canvas.Font := oFont;
  FLabel1.Caption := ' '+FHeading+' ';
  FLabel1.Left := (Width div 2) - (widthT div 2);

procedure TvPanel.setData(Value: String);
if Value <> FHeading then
  FData := Value;
  FEdit1.Text := FData;

procedure Register;
RegisterComponents('Jack', [TvPanel]);


 = = = = = = = = = = = = = = = = = = = = =
I hope this will help

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.