Board index » cppbuilder » Creating arrays of components at runtime

Creating arrays of components at runtime

Could someone furnish, or direct me to, code to create arrays of components
at runtime? I thought I remembered seeing something here in the past that
this was possible using the vector class.

TIA, Chuck Kennedy

 

Re:Creating arrays of components at runtime


Hi, Chuck!

TList    *Control = new TList;

for (int Index = 0; Index < NumberOfControlsToCreate; Index++)
{
    Control->Add(new TButton(this));
    dynamic_cast<TButton *>(Control[Index])->Parent = this;

Quote
};

Try that.

------
Mark Cashman (TeamB - C++ Builder), creator of The Temp{*word*203}Doorway at
http://www.temporaldoorway.com
- Original digital art, writing, music and more -
C++ Builder / JBuilder Tips and The C++ Builder Programmer's Webring
(Join us!)
http://www.temporaldoorway.com/programming/index.htm
------

Re:Creating arrays of components at runtime


Mark,
Thanks for the suggestion, but - tried it, it gives E2031 Cannot cast from
"TList" to 'TButton*' on the line with the dynamic_cast.
I've gotten essentially the same error on a couple of other ways I've tried.
????
Chuck

Re:Creating arrays of components at runtime


Sorry, Chuck, you need

    dynamic_cast<TButton *>(Control->Items[Index])->Parent = this;

I was thinking in Delphi not C++

------
Mark Cashman (TeamB - C++ Builder), creator of The Temp{*word*203}Doorway at
http://www.temporaldoorway.com
- Original digital art, writing, music and more -
C++ Builder / JBuilder Tips and The C++ Builder Programmer's Webring
(Join us!)
http://www.temporaldoorway.com/programming/index.htm
------

Re:Creating arrays of components at runtime


Hello Chuck,

"Chuck Kennedy" <cwk...@lcc.net> schreef in bericht
news:8vglic$k5d5@bornews.inprise.com...

Quote
> Mark,
> Thanks for the suggestion, but - tried it, it gives E2031 Cannot cast from
> "TList" to 'TButton*' on the line with the dynamic_cast.
> I've gotten essentially the same error on a couple of other ways I've
tried.
> ????

Hmm, apart from the fact that you could set the Parent property for your new
TButton before you add it to the list<g>, you ultimately will have to use
that list. For indexed retrieve use the TList Items property.

dynamic_cast<TButton*>(List->Items[index])->Parent = this;

should work, as well as:

((TButton*)List->Items[index])->Parent = this;

btw.

Place your cursor on the word TList in the IDE editor window and press F1,
All will be revealed...;-))

Quote
> Chuck

--
Greetings from rainy Amsterdam

                Jan

email: bijs...@worldonline.nl
http://home.worldonline.nl/~bijster

Re:Creating arrays of components at runtime


Mark, your last post gives E2307, Type void is not a defined class with
virtual functions.

J. A.,  your
        ((TButton*)List->Items[Index])->Parent = this;

     followed by
        ((TButton*)List->Items[Index}->Caption = "Button";
        etc., does the job.

Thanks much to both of you; Happy Thanksgiving.

Chuck

Other Threads