Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
The C++ Builder (and Turbo C++) TForm class ('Form' from now on) can be created either statically or dynamically.
Consider creating Forms dynamically when:
When you want to dynamically create a Form
A Form can be created dynamically as follows:
//Put this line among the other #includes |
Sure you can use a plain pointer, but then don't forget to delete it. And if you don't want to forget to delete this pointer (among others), use a std::auto_ptr.
Instead of passing 'this', you might sometimes consider passing '0' as an argument to the constructor of TFormDynamic.
In the code snippet above, the Form called TFormDynamic is constructed using a pointer to the TFormMain Form. This enables the newly created TFormDynamic to be potentially able to communicate with the TFormMain.
The constructor of a Form takes as an argument the TComponent that has created it. Therefore, you can easily use it locally:
//Put this line among the other #includes |
You can also make the TFormMain pointer a member variable of TFormDynamic:
//UnitFormDynamic.h |
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.