Vcl.Forms.TCustomForm.CreateNew

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

constructor CreateNew(AOwner: TComponent; Dummy: Integer  = 0); virtual;

Properties

Type Visibility Source Unit Parent
constructor public Vcl.Forms.pas Vcl.Forms TCustomForm

Description

Creates and initializes a new form.

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.

The CreateNew method calls Create and InitializeNewForm. This does not call the OnCreate event upon form creation.

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.

See Also