RAD Studio VCL Reference
TDataModule.CreateNew Constructor

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

constructor CreateNew(AOwner: TComponent; Dummy: Integer = 0); virtual;
virtual __fastcall TDataModule(TComponent * AOwner, int Dummy = 0);

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);


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