home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / Runimage / Delphi50 / Demos / Midas / Pooler / srvrdm.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-08-11  |  2.9 KB  |  81 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {        Midas RemoteDataModule Pooler Demo             }
  4. {                                                       }
  5. {*******************************************************}
  6.  
  7. unit SrvrDM;
  8.  
  9. {
  10.   This is the Remote Data Module (RDM) that is going to be pooled.
  11.   The differences between this RDM and a regular RDM are as follows;
  12.   1) In order to share RDMs the client must be stateless. This means that the
  13.      all calls that come into the server, must not rely on any informatin passed
  14.      in previous calls.
  15.   2) The RDMs need to run in their own thread which is why the factory
  16.      constructor is specifying tmApartment as the threading model.  tmFree or
  17.      tmBoth could also be used if the server is written to support Free threading.
  18.   3) This class is an internal accesible class only and is not registered in the
  19.      registry.  All access to this object is done from the pooler object.  If
  20.      you look in the Type Library you will see 2 different CoClasses for this
  21.      project.  One is for this class and one is for the Pooler.
  22. }
  23.  
  24. interface
  25.  
  26. uses
  27.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  28.   ComServ, ComObj, VCLCom, StdVcl, ActiveX, DataBkr, Server_TLB,
  29.   Db, DBTables, Provider;
  30.  
  31. type
  32.   TPooledRDM = class(TRemoteDataModule, IPooledRDM)
  33.     Session1: TSession;
  34.     Database1: TDatabase;
  35.     Query1: TQuery;
  36.     DataSetProvider1: TDataSetProvider;
  37.     procedure DataSetProvider1BeforeGetRecords(Sender: TObject;
  38.       var OwnerData: OleVariant);
  39.   private
  40.     { Private declarations }
  41.   public
  42.     { Public declarations }
  43.   end;
  44.  
  45. var
  46. { Need a reference to the ClassFactory so the pooler can create instances of the
  47.   class. }
  48.   RDMFactory: TComponentFactory;
  49.  
  50. implementation
  51.  
  52. {$R *.DFM}
  53.  
  54. { Since this is a stateless server, before records are fetched, the query needs
  55.   to be positioned to the correct location. The client passes the query and the
  56.   value of the first field for the last record it fetched.  If you are fetching
  57.   all records then you don't need to locate the last record.  If the query
  58.   isn't changing, then you don't need to pass the query to the server.}
  59. procedure TPooledRDM.DataSetProvider1BeforeGetRecords(Sender: TObject;
  60.   var OwnerData: OleVariant);
  61. begin
  62.   try
  63.     Query1.Close;
  64.     Query1.SQL.Text := OwnerData[0];
  65.     if not VarIsNull(OwnerData[1]) and not VarIsEmpty(OwnerData[1]) then
  66.     begin
  67.       Query1.Open;
  68.       if not Query1.Locate(Query1.Fields[0].FieldName, OwnerData[1], []) then
  69.         raise Exception.Create('Record not found');
  70.       Query1.Next;
  71.     end;
  72.   finally
  73.     OwnerData := NULL;
  74.   end;
  75. end;
  76.  
  77. initialization
  78.   RDMFactory := TComponentFactory.Create(ComServer, TPooledRDM,
  79.     Class_PooledRDM, ciInternal, tmApartment);
  80. end.
  81.