Board index » delphi » Adding lines in a the constructor of a component based on a combobox

Adding lines in a the constructor of a component based on a combobox

Hello, i'm chassing for some help.

Here is my problem :

I'm trying to create a component based on a TWincontrol which contains a
TCombobox and a TEdit.
I would like to fill the Combobox with the label of the 12 months in the
contructor of my component.
My problem is that Delphi can't create the lines and a the following
message appears  :
"The component '' has no parent." I suppose it's because my component is
not created yet.

What can I do to solve this problem.

Here follows a part of the code I wrote :

TMyNewClass = Class(TWinControl)
        MonthCombo : TCombobox;
        YearEdit   : TEdit;
        ...

        public
                contructor create(Aowner : TComponent); override;

        ...

end;

...

constructor TMyNewClass.Create(Aowner : TComponent);
var i : integer;
begin
        Inherited Create(Aowner);

        MonthCombo := TCombobx.Create(Self);
        MonthCombo.Parent := Self; // is it useful ??
        YearEdit   := TEdit.Create(Self);
        YearEdit.Parent := Self; // is it useful ??
        ...

        for i:=1 to 12 do
                MontCombo.Items.Add(LongMonthName[i]);
end;

Thank you very much for your help.

 

Re:Adding lines in a the constructor of a component based on a combobox


On Wed, 04 Mar 1998 20:45:16 +0100, RH <rho...@club-internet.fr>
wrote:

Quote
>Hello, i'm chassing for some help.

>Here is my problem :

>I'm trying to create a component based on a TWincontrol which contains a
>TCombobox and a TEdit. I would like to fill the Combobox with the label of
>the 12 months in the contructor of my component. My problem is that Delphi
>can't create the lines and a the following message appears :
>"The component '' has no parent." I suppose it's because my component is
>not created yet.

>What can I do to solve this problem.
>Here follows a part of the code I wrote :

>TMyNewClass = Class(TWinControl)
>        MonthCombo : TCombobox;
>        YearEdit   : TEdit;
>        public
>                contructor create(Aowner : TComponent); override;
>end;

>constructor TMyNewClass.Create(Aowner : TComponent);
>var i : integer;
>begin
>        Inherited Create(Aowner);

>        MonthCombo := TCombobx.Create(Self);
>        MonthCombo.Parent := Self; // is it useful ??
>        YearEdit   := TEdit.Create(Self);
>        YearEdit.Parent := Self; // is it useful ??
>        ...

>        for i:=1 to 12 do
>                MontCombo.Items.Add(LongMonthName[i]);
>end;

>Thank you very much for your help.

The parent of a component is the TWinControl upon which the other
component is displayed.

If you, for example, drop a TButton on a TPanel, which in turn is
located on a TForm, you will find that while TButton.Owner is the
TForm, TButton.Parent is the TPanel. Without a Parent, any references
to a TWinControl that would change the appearance of the TWinControl
will fail.

You've already found the solution: MonthCombo.Parent := Self is a
valid assignment and will solve the problem.

Bonne chance.

Other Threads