RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TCustomForm.CreateNew Constructor

Creates and initializes a new form.

Pascal
constructor CreateNew(AOwner: TComponent; Dummy: Integer = 0); virtual;
C++
virtual __fastcall TCustomForm(TComponent * AOwner, int Dummy = 0);

Use CreateNew instead of Create to create a form without using the associated .DFM file to initialize it. Always use CreateNew if the TCustomForm descendant is not a TForm object or a descendant of TForm

CreateNew bypasses the streaming in of the previously-associated .DFM file. If the form contains visual components, therefore, you must stream in an external .DFM to bind the visual components with their classes. If the newly created form has an external .DFM file, then you can follow the call to CreateNew with a call to InitInheritedComponent. If you need to create the .dfm file for the new form instance, bracket the call to CreateNew with calls to WriteComponentResFile and ReadComponentResFile. The following code sequence 

 

  1. streams out an external .DFM file;2. creates a new form disassociated from any .DFM resource file;3. streams in the external .DFM file and binds it to this new form.
WriteComponentResFile('Temp.dfm', Form1);
...

Form2 := TForm.CreateNew(Application);

ReadComponentResFile('Temp.dfm', Form2);

Warning: Using CreateNew instead of Create can cause unpredictable results because most forms are written assuming their controls will be created from the .DFM file.
CreateNew is called by the Create method.  

The first argument, AOwner, is the owner of the form (usually the application or another form is the owner). The second argument, Dummy, defaults to 0 and is not used by this constructor. The system passes 0 by default if this constructor is passed only the first argument, AOwner. 

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!