I'm not quite sure about what I'm trying to talk now, but based on many experimentation, I have following conclusion.
In web-server application, you have to avoide using global-scope variables. You can have more than one datamodules (including webmodule) in Lazarus, which is not allowed in Delphi (at least up to Delphi 7).
Let's assume that you have one webmodule and one normat datamodule and the latter has database connections and related methods operating on the database.
I listed up structure normally created, but think that the variable of the datamodule must be declared within web-module, as explained in the comments.
unit wm_unit;
interface
uses dm_unit;
type
Twm1 = class(TFPWebModule)
.......
private
wdm1 : Tdm1; // You have to define the variable here.
end;
var
wm1: Twm1; // Actually this variable seems never used.
implementation
.....
procedure Twm1.DataModuleCreate(Sender: TObject);
begin
wdm1 := Tdm1.Create(Self); // And Created here
end;
procedure Twm1.DataModuleDestroy (Sender: TObject);
begin
wdm1.Free; // Freed here. But I think this is not necessary as it is owned by Self.
end;
initialization
RegisterHTTPModule('wm1', Twm!);
end.
// ----------------------- Data Module
unit dm_unit;
interface
type
Tdm1 = class(TDataModule)
.......
end;
var
dm1: Tdm!; // this variable SHOULD NOT be used.
implementation
.....
end.
Please anyone advise me if I'm wrong.