| View previous topic :: View next topic |
| Author |
Message |
Nathan Guest
|
Posted: Mon Nov 24, 2003 11:31 pm Post subject: add data to Tstrings |
|
|
Hi everybody
I create a TComboBox with some data in the items when I add it to form I
got a ErrMsg "Control has no parent window" I debug it I see it stop when
it add the data to the items property
Here is the my code
TdsDateComboBox = class(TCustomComboBox);
....
constructor TdsDateComboBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Style:= csDropDownList;
Items.Add('All');
Items.Add('Today');
Items.Add('This Week');
Items.Add('This Week-to-date');
Please reply thanks
Nathan
|
|
| Back to top |
|
 |
Yorai Aminov (TeamB) Guest
|
Posted: Tue Nov 25, 2003 12:22 am Post subject: Re: add data to Tstrings |
|
|
On Mon, 24 Nov 2003 18:31:45 -0500, "Nathan" <nerenthal (AT) hotmail (DOT) com>
wrote:
| Quote: | I create a TComboBox with some data in the items when I add it to form I
got a ErrMsg "Control has no parent window"
|
You're trying to access the combo box items in the constructor.
Unfortunately, the items list is implemented as a wrapper around the
standard combo box messages. This means they are only accessible once
a window handle is created.
You can override the CreateWnd method and add your items then. Note
that the method is called whenever the window is recreated, so you'll
probably want to set a flag somewhere to avoid inserting the items
more than once.
---
Yorai Aminov (TeamB)
http://develop.shorterpath.com/yorai
(TeamB cannot answer questions received via email.)
|
|
| Back to top |
|
 |
JED Guest
|
Posted: Tue Nov 25, 2003 12:29 am Post subject: Re: add data to Tstrings |
|
|
Nathan wrote:
| Quote: | Hi everybody
I create a TComboBox with some data in the items when I add it to
form I got a ErrMsg "Control has no parent window" I debug it I see
it stop when it add the data to the items property
|
You could override the Loaded method and add the items there.
HTH,
jed
|
|
| Back to top |
|
 |
Peter Below (TeamB) Guest
|
Posted: Tue Nov 25, 2003 6:46 pm Post subject: Re: add data to Tstrings |
|
|
In article <3fc294ba$1 (AT) newsgroups (DOT) borland.com>, Nathan wrote:
| Quote: | I create a TComboBox with some data in the items when I add it to form I
got a ErrMsg "Control has no parent window" I debug it I see it stop when
it add the data to the items property
Here is the my code
TdsDateComboBox = class(TCustomComboBox);
constructor TdsDateComboBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Style:= csDropDownList;
Items.Add('All');
Items.Add('Today');
Items.Add('This Week');
Items.Add('This Week-to-date');
|
As indicated by the other replies you cannot do things in the constructor
that require the controls window handle to exist. But using Items.Add should
work without the handle, the control will buffer the data into a temp
TStringlist instance. What does require the window handle, however, is an
attempt to set the ItemIndex. You should move that to an overriden CreateWnd
or SetParent method.
--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be
|
|
| Back to top |
|
 |
|