From RAD Studio API Documentation
Jump to: navigation, search


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


Type Visibility Source Unit Parent
constructor public System.Classes.pas System.Classes TDataModule


Creates an instance of a data module and registers with the global screen object.

Use CreateNew instead of Create to create a data module without using the associated .form file to initialize it.

Warning: Using CreateNew instead of Create can cause unpredictable results because most data modules are written assuming their controls will be created from the form file.

CreateNew calls the inherited constructor, and then informs the global screen object of the existence of the data module.

The first argument, AOwner, is the owner of the data module (usually the application). 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.

CreateNew bypasses the streaming in of the previously associated form file. Therefore, you must stream in an external form file to bind the visual components with their classes. You can stream in the previously associated form file by calling InitInheritedComponent. To stream in a different form file, bracket the call to CreateNew with calls to WriteComponentResFile and ReadComponentResFile. The following code sequence

1. streams out an external form file.

2. creates a new data module disassociated from any form file;

3. streams in the external form file and binds it to this new data module.

WriteComponentResFile('Temp.xfm', DataModule1);
DataModule2 := TDataModule.CreateNew(Application);
ReadComponentResFile('Temp.xfm', DataModule2);

See Also