Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TComboBox Descendent

2 views
Skip to first unread message

Mark Bracey

unread,
Feb 22, 2000, 3:00:00 AM2/22/00
to
It might be because the component is not totally created yet, your
Items.Add('') are what are crashing the component.

Try putting them in a procedure Loaded; override; method instead;

The ComboBox consists of a an Edit and a ListBox. At this point in the
creation process, the both componens are not totally created, so when
you try to add the items the ListBox control underneath is crashing.

Michael Finch wrote:
>
> I have the need to create a custome Combo Box. Basically all I want to do is
> make a standard Combo Box, change a few properties (default font, size,
> style etc) and add 2 or 3 items into the string list.
>
> I have successfully done everything but get the 2 or 3 items into the string
> list. Every time I try to add items I either crash the component (I'm
> learning here!) or, if I get it to compile correctly, every time I try to
> put the component on a form, I get an error 'Control '' has no Parent'.
>
> Can anyone help me to populate the list, or explain what i'm doing wrong
> here?
>
> It seemed like such a simple task.......argggghhhh.
>
> Thanks
>
> This is all I really want to do!...it can't be that hard........can it?
>
> constructor TMTYNSCombo.Create(AOwner: tComponent);
> begin
> inherited Create(AOwner);
> Font.Name := 'Courier New';
> Font.Size := 10;
> DropDownCount := 3;
> Width := 75;
> Items.Add('Yes');
> Items.Add('No');
> Items.Add('*');
> Style := csDropDownList;
> end;

--
Having a Delphi Day...

Michael Finch

unread,
Feb 23, 2000, 3:00:00 AM2/23/00
to

Michael Finch

unread,
Feb 23, 2000, 3:00:00 AM2/23/00
to
Her is the answer I came up with. simple really....when you understand what
happens to the component when it is created.

Thanks Mark

type
TMTYNCombo = class(TComboBox)
private
{ Private declarations }
protected
{ Protected declarations }
procedure Loaded; override;
public
{ Public declarations }
constructor Create(AOwner: tComponent); override;
published
{ Published declarations }
end;

procedure Register;

implementation

constructor TMTYNCombo.Create(AOwner: tComponent);


begin
inherited Create(AOwner);
Font.Name := 'Courier New';
Font.Size := 10;

DropDownCount := 2;
Width := 75;
Style := csDropDownList;
end;

procedure TMTYNCombo.Loaded;
begin
inherited Loaded; { always call the inherited Loaded first! }


Items.Add('Yes');
Items.Add('No');

ItemIndex := 1;
end;


Michael Finch <mi...@mmtech.com.au> wrote in message
news:88v5rh$5i...@bornews.borland.com...

Unknown

unread,
Feb 23, 2000, 3:00:00 AM2/23/00
to
On Wed, 23 Feb 2000 10:05:22 +1030, "Michael Finch"
<mi...@mmtech.com.au> wrote:

>I have successfully done everything but get the 2 or 3 items into the string
>list. Every time I try to add items I either crash the component (I'm
>learning here!) or, if I get it to compile correctly, every time I try to
>put the component on a form, I get an error 'Control '' has no Parent'.
>

Use overriden CreateWnd to add items in combobox

type
TMTYNSCombo = class(TComboBox)
protected
procedure CreateWnd; override;
public
constructor Create(AOwner: TComponent); override;
end;


procedure TMTYNSCombo.CreateWnd;
begin
inherited CreateWnd;


> Items.Add('Yes');
> Items.Add('No');
> Items.Add('*');

end;

>
>constructor TMTYNSCombo.Create(AOwner: tComponent);
>begin
> inherited Create(AOwner);
> Font.Name := 'Courier New';
> Font.Size := 10;
> DropDownCount := 3;
> Width := 75;

> Style := csDropDownList;
>end;
>


HTH
ain


0 new messages