Solved

Borland C++ Builder Add Control at Runtime

Posted on 2001-07-31
4
1,092 Views
Last Modified: 2008-02-26
I would like to add a TPanel control during runtime.  

In the Tform1 class:  
   TPanel tmp.  

In Tform1 constructor:
   tmp = new TPanel(Owner);
   tmp->Top = 100;
   tmp->Left = 100;
   tmp->Width = 100;
   tmp->Height = 100;
   tmp->Visible = true;

When the form is shown during runtime, there is no panel.  Also tried placing the code in the forms OnShow handler with no results.


0
Comment
Question by:lirtua
  • 2
4 Comments
 
LVL 6

Expert Comment

by:graham_k
ID: 6340268
I'll check at home tonight & post tomorow.   It looks ok, all that I can think of is that you might want to set tmp->Enabled = true and I would probably use tmp = new TPanel(Self); so tha the Form is the owner of teh new panel.

I'll let you know tomorrow at latest.

~graham();
0
 
LVL 2

Expert Comment

by:LoungeLizard
ID: 6342857
tmp = new TPanel(Form1);

should do the trick. The form is the owner of the panel, meaning that the panel should be displayed on the form.

Also, might a good idea to put it in the "OnShow" event, after the form has been contstructed and initialsed.
0
 
LVL 6

Accepted Solution

by:
graham_k earned 15 total points
ID: 6343423
this might sound silly, but I seem to dimly rememebr being stumpd by the same thing, and I reckon that you need to set the ->Parent property - which you would naturally assume the constrcutor would do.

So :

temp = new TPanel(self)
temp->Parent = self;

the only other thing which I do in addition to what you do is to set temp->FormStyle but I doubt if it is that.

Try setting ->Parent & let us know how it goes.

Good luck!

~graham();
0
 

Author Comment

by:lirtua
ID: 6520641
Thank you graham.  Here is the final source code that was placed in a menu item click event:

  tmp = new TPanel(frmMain);
  tmp->Parent = frmMain;
  tmp->Top = 5;
  tmp->Left = 5;
  tmp->Width = 5;
  tmp->Height = 5;
  tmp->Visible = true;

And in the form's class:

TPanel *tmp;


0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now