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...
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...
>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