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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Component SubComponent

Status
Not open for further replies.

efabor

Programmer
Joined
Feb 6, 2005
Messages
2
Location
CA
Hi there;

I can't solve this problem. I tried many things (reading VisualCLX, debuging...)

I want to create my own component "TH2mPanel" based on TPanel. And I want to integrate a TLabel subcomponent "TLabelFrom". At design time I can drop my THmPanel in the Form; I can resize it, move it and changing its properties. But not the SubComponent. I changed the way I create the subcomponent in the TH2mPanel.Create method like this

fLabelFrom:= TLabel.Create(AOwner);
fLabelFrom.Parent:= Self;

Now I am able to act on the subcomponent at desing time (move it, resize it...). But each time I will open the form, the TH2mPanel.Create method will add a new TLabel to the form and if I change the creation of TLabel like this

fLabelFrom:= TLabel.Create(nil);

I won't be able to manipulate the subcomponent at desing time.

Please if u have any idea or type, let me know
Thanx

This is the source code of my class.

unit QH2mPanel;

interface

uses
SysUtils, Classes,TypInfo, QControls, QExtCtrls, QStdCtrls, QDialogs;


type
TH2mPanel = class(TPanel)
private
{ Private declarations }
fLabelFrom: TLabel;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
published
{ Published declarations }
property LabelFrom: TLabel read fLabelFrom write fLabelFrom;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('H2m', [TH2mPanel]);
end;

{ TH2mPanel }

constructor TH2mPanel.Create(AOwner: TComponent);

begin
inherited Create(AOwner);
Self.Caption:= ' ';
Self.BevelInner:= bvLowered;
Self.BevelOuter:= bvRaised;

fLabelFrom:= TLabel.Create(AOwner);
fLabelFrom.Parent:= Self;
fLabelFrom.Caption:= 'From';
end;

end.
 
I may be misunderstanding here, but you seem to be saying that after you've dropped a TH2mPanel on a form, each time you open the form more and more labels appear in this panel component. Is this what you're saying?

What I don't understand is why each time you "open the form, the TH2mPanel.Create method will add a new TLabel to the form". Surely only one label will be created per panel?




Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
I suggest that you make a Frame that consists of a TPanel and a TLabel (and any other components).

You can then drop the Frame on your form and alter the TLabel component quite easily.

Frames are a quite flexible feature of Delphi which possibly don't get the attention they deserve.

Andrew
Hampshire, UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top