Adding an object to a form at runtime

First off I'm using C++ builder 3... similar to Delphi ... so any delphi code will help me ...I'd post my question in C++ section, but since it's a VCL thing, you guys are probably my best source.

I want to add a DriveComboBox to a form at run time.

After declaring a pointer variable to the object, and creating the object... I can access it's properties, but I can't see it on my form.... Is there a way to do this??

my code in C++ is

TDriveComboBox *Dr1;

Dr1 = new TDriveComboBox(Form1);

....
now properties can be accessed...
but DriveComboBox is NOT visible on the form
rafyAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
arhConnect With a Mentor Commented:
You should do this just after creating your control:
Dr1.parent:=Form1;
0
 
arhCommented:
sorry, it was Delphi syntax..
Dr1.Parent=Form1; // right?
0
 
rafyAuthor Commented:
Dr1->Parent = Form1;
to be exact...

Perfect, thanks.

By the way, do I have to free the memory that I allocated for this object, or will the form automatically do the clean up for me when I close it.
0
 
arhCommented:
Owner (which you give as an argument to constructor call) will always destroy
component object.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.