• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 177
  • Last Modified:

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
0
rafy
Asked:
rafy
  • 3
1 Solution
 
arhCommented:
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now