Sign in to follow this  

dynamic object creation in borland c++ builder

This topic is 4807 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

does anyone know the code to create something dynamically in borland ex. when i press a button create a panel... it uses something like new TPanel Parent Form1 i really dont know, but i forgot it and i cant find it in any of my projects that i have done. could someone help me plz thanks

Share this post


Link to post
Share on other sites
i know that it is something like

global:

TPanel* Panels[10];
int x = 0;

void __fastcall TForm1::Button1Click(TObject *Sender)
{
Panels[x] = new TPanel();
x++;
}
/------------------------------------------

i tried that but it gives me an error for the TPanel thing

even if i try

Panels[x] = new TPanel(Panels[x]);


it runs!
but it doesnt work... :(

help plz...

Share this post


Link to post
Share on other sites
Did you try looking at the help on TPanel? It says specifically that you need to specify an owner. That's either another component or a window. Where is this panel suppose to be created? What is it part of? Is it just a panel on the desktop? If so then you at a minimum need to tell it to create it on the desktop if that would even work.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
i know, i have to create it on the form...thats why i said it has something to do with Parent Form1 and what not

you didnt help me, i have looked in every help file i have, and all it says is

Panel1 = new TPanel();

thats it....its not just panel or anything...its any object

Image1 = new TImage();
Button1 = new TButton();

anything....if you use borland you would know what im trying to say...

Share this post


Link to post
Share on other sites
IIRC, when i used Delphi (it uses almost same VCL) , i had to create it passing parent, and maybe also make it visible.. something like show(). But i don't sure, i have never used VCL really much.

Share this post


Link to post
Share on other sites
Hi GT70sgt,

Something like this should help you out, its been a while but I used to use BCB myself :)


TPanel *Panel1 = new TPanel(this);
Panel1->Parent = this;
Panel1->Name = "PANELCOMPONENT";
Panel1->Caption = "BLAH";
Panel1->Left = 10;
Panel1->Top = 10;
Panel1->Width = 150;
Panel1->Height = 50;
Panel1->Show();


Dont forget to delete the panels you create - if you need any more help just let me know

Chris.

Share this post


Link to post
Share on other sites

This topic is 4807 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this