Recent

Author Topic: Rather important thing in Web server application  (Read 260 times)

egsuh

  • Sr. Member
  • ****
  • Posts: 464
Rather important thing in Web server application
« on: May 25, 2020, 10:32:03 am »
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. 


Code: Pascal  [Select][+][-]
  1. unit wm_unit;
  2. interface
  3.  
  4. uses dm_unit;
  5.  
  6.  type
  7.     Twm1 = class(TFPWebModule)
  8.            .......
  9.  
  10.     private
  11.         wdm1 : Tdm1;   // You have to define the variable here.
  12.     end;
  13.  
  14. var
  15.    wm1: Twm1;    // Actually this variable seems never used.  
  16.  
  17. implementation
  18.     .....
  19.  
  20. procedure Twm1.DataModuleCreate(Sender: TObject);
  21. begin
  22.     wdm1 := Tdm1.Create(Self);         // And Created here
  23. end;
  24.  
  25. procedure Twm1.DataModuleDestroy (Sender: TObject);
  26. begin
  27.      wdm1.Free;    // Freed here. But I think this is not necessary as it is owned by Self.
  28. end;
  29.  
  30. initialization
  31.    RegisterHTTPModule('wm1', Twm!);
  32. end.
  33.  
  34.  
  35. // ----------------------- Data Module  
  36. unit dm_unit;
  37. interface
  38.  
  39.  type
  40.     Tdm1 = class(TDataModule)
  41.            .......
  42.     end;
  43.  
  44. var
  45.    dm1: Tdm!;            // this variable SHOULD NOT be used.
  46. implementation
  47.     .....
  48. end.
  49.  


 Please anyone advise me if I'm wrong.

Thaddy

  • Hero Member
  • *****
  • Posts: 10516
Re: Rather important thing in Web server application
« Reply #1 on: May 25, 2020, 10:47:52 am »
I seriously advice you to play "Oh, well"
Code: Pascal  [Select][+][-]
  1. var
  2.    dm1: Tdm!;            // this variable SHOULD NOT be used.
  3.  
As is the exclamation mark.........................................................................
Writing invalid code is easy.

 

TinyPortal © 2005-2018