Subject | Re: [IBO] DataModule question |
---|---|
Author | Harald Klomann |
Post date | 2001-03-29T15:17:58Z |
Jason Wharton wrote:
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
> Often times I design my forms so that there can be multiple instances ofThere is also a very easy way, to have multiple instances of forms when using
> them so I put the transaction, dataset and datasource components right on
> it.
>
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