Board index » cppbuilder » create controls at run time

create controls at run time


2008-02-05 02:40:39 AM
cppbuilder108
I would like to create a TForm at run-time and then add some controls on this form. Could you please give me a example code?
Thanks for help
 
 

Re:create controls at run time

"didan" < XXXX@XXXXX.COM >wrote in message
Quote
I would like to create a TForm at run-time and then add some controls on
this form. Could you please give me a example code?
If you want to create a form at run-time that you have designed then you can
create it a couple of ways:
// This creates a form with 'Application' as its owner. This means that
// the form will get destroyed when the application object gets destroyed
// (which is when the application closes). You can use other TComponent
// descendants here instead of 'Application' (the main form for example).
TMyForm* form = new TMyForm(Application);
// This creates a form with no owner. You are responsible for freeing
// the form when you are finished using it.
TMyForm* form = new TMyForm(NULL);
// You can use the VCL way of creating the form (which is basically the
// same as the first option I showed above)
TMyForm* form;
Application->CreateForm(__classid(TMyForm), &form);
If you want to create a generic blank form that is not based on any visually
designed form then use this code instead:
// This will create a form and instruct the VCL to skip the resource
// loading step
TForm* form = new TForm(Application, 0);
// ... or with no owner
TForm* form = new TForm(NULL, 0);
Once you have your form you can create any control or component you'd like
(assuming you've included the correct header files). For example, if you'd
like to create an edit control:
TEdit* edit = new TEdit(form);
edit->Parent = edit;
edit->Left = 40;
edit->Top = 20;
All other controls behave the same way.
Post again if you need more pointers or if a concept is not making sense.
HTH,
Clayton
 

Re:create controls at run time

Hi Clayton
Thanks!!! great help
 

{smallsort}