Board index » delphi » Virtual TComboBox : EStackOverflow

Virtual TComboBox : EStackOverflow

Hello,

I need a virtual TComboBox, because one of my Components need a combobox for
his output and my project doesn't have a form!
So I tried:

var ComboBox1 : TComboBox;

procedure xyz;
begin
          combobox1:=TComboBox.Create(combobox1);
          combobox1.parent:=combobox1;
          combobox1.Items[0]:='test';
          showmessage(combobox1.items[0]);
end;

But I get an EStackOverflow-error! What is the problem? What do I wrong?

Thank you in advance
Chris

 

Re:Virtual TComboBox : EStackOverflow


Quote
In article <3b3c4db7_1@dnews>, Christian wrote:
> I need a virtual TComboBox, because one of my Components need a combobox for
> his output and my project doesn't have a form!
> So I tried:
> var ComboBox1 : TComboBox;
> procedure xyz;
> begin
>           combobox1:=TComboBox.Create(combobox1);
>           combobox1.parent:=combobox1;
>           combobox1.Items[0]:='test';
>           showmessage(combobox1.items[0]);
> end;

> But I get an EStackOverflow-error! What is the problem? What do I wrong?

You are trying to be smart without knowing what you are doing <g>. You cannot
parent a control to itself. Components that are based on Windows controls
usually need a window handle to function. And they can only get a window
handle if they are contained by some other windowed control that already has a
handle. So if you do an operation on a TwinControl descendent that requires
the window handle to be there it first checks if it already has one
(TWinControl.GetHandle calls HandleNeeded). TwinControl.HandleNeeded does
this:

  if FHandle = 0 then
  begin
    if Parent <> nil then Parent.HandleNeeded;
    CreateHandle;
  end;

So it first makes sure the parent has a handle. If Parent = Self this will of
course result in infinite recursion...

Why does your component require a TCombobox? If it needs some way to store a
list of strings it should use a TStringlist internally.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.

Other Threads