01-24-2024, 09:14 AM
Hi Davide,
Been there, done that, a long time ago.
IMO, the best way to do it is using code to link things instead of properties via Object Inspector.
Something like this:
Add a conditional define to your IW project (something like IW) and use it to isolate IntraWeb-specific code.
Connect the DBConnection to the DataSets via code, using a code like this (that you can write once in a TDataModuleBase that would be the ancestor of all your DataModules).
This simple arrangement works well for this kind of scenario.
Have in mind that global variables like that one that Delphi creates for you (var DataModule1: TDataModule1) is a no-no in IntraWeb applications.
Been there, done that, a long time ago.
IMO, the best way to do it is using code to link things instead of properties via Object Inspector.
Something like this:
Code:
unit Unit1;
interface
uses
{$IFDEF IW}
UserSessionUnit,
{$ENDIF}
System.SysUtils, System.Classes, FireDAC.Comp.Client;
type
TDataModule1 = class(TDataModule)
procedure DataModuleCreate(Sender: TObject);
private
{ Private declarations }
FDBConnection: TFDConnection;
public
{ Public declarations }
end;
{$IFNDEF IW}
var
DataModule1: TDataModule1; // NEVER USE THIS IN AN IW application
{$ENDIF}
implementation
{$R *.dfm}
procedure TDataModule1.DataModuleCreate(Sender: TObject);
var
i: Integer;
DS: TFDRdbmsDataSet;
begin
{$IFDEF IW}
FDBConnection := UserSession.MainConnection;
{$ELSE}
FDBConnection := SomeDataModule.MainConnection;
{$ENDIF}
for I := 0 to ComponentCount - 1 do
begin
if Components[i] is TFDRdbmsDataSet then
begin
TFDRdbmsDataSet(Components[i]).Connection := FDBConnection;
end;
end;
end;
end.Add a conditional define to your IW project (something like IW) and use it to isolate IntraWeb-specific code.
Connect the DBConnection to the DataSets via code, using a code like this (that you can write once in a TDataModuleBase that would be the ancestor of all your DataModules).
This simple arrangement works well for this kind of scenario.
Have in mind that global variables like that one that Delphi creates for you (var DataModule1: TDataModule1) is a no-no in IntraWeb applications.

