Subject Re: [IBO] DataModule question
Author Harald Klomann
Jason Wharton wrote:
> Often times I design my forms so that there can be multiple instances of
> them so I put the transaction, dataset and datasource components right on
> it.
>

There is also a very easy way, to have multiple instances of forms when using
data modules :

1.) Create a empty data modul
-----------------------------

type

TdmMultiInstance = class(TDataModule)
procedure DataModuleCreate(Sender: TObject);
end;

procedure TdmMultiInstance.DataModuleCreate(Sender: TObject);
begin
Name := MakeUniqueName(Name);
end;

function MakeUniqueName(const Name: string): string;
var i: Integer;
begin
i := 0;
Result := '';
if Assigned(FindGlobalComponent) then begin
Result := Name;
while FindGlobalComponent(Result) <> nil do begin
Inc(i);
Result := Format('%s_%d', [Name, i]);
end;
end;
end;

2.) Create your new Datamodules from TdmMultiInstance via
inheritance, Delphi File->New->YourDatamodules ....

type
TMyNewDataModul = class(TdmMultiInstance)
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;


3.) From your forms:

MyDataModul := TMyNewDataModul.Create(Self)
.
.
.


that´s all - and it works !


Harald