ProviderBeforeGetRecords (Delphi)
Description
can create instances of the class. } RDMFactory: TComponentFactory;
implementation
{$R *.dfm}
{ Since this is a stateless server, before records are fetched, the query needs
to be positioned to the correct location. The client passes the query and the value of the first field for the last record it fetched. If you are fetching all records, then you do not need to locate the last record. If the query is not changing, then you do not need to pass the query to the server.}
Code
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComServ, ComObj, VCLCom, StdVcl, ActiveX, DataBkr, Server_TLB,
Db, DBTables, Provider, Variants;
type
TPooledRDM = class(TRemoteDataModule, IPooledRDM)
Session1: TSession;
Database1: TDatabase;
Query1: TQuery;
DataSetProvider1: TDataSetProvider;
procedure DataSetProvider1BeforeGetRecords(Sender: TObject;
var OwnerData: OleVariant);
protected
class procedure UpdateRegistry(Register: Boolean; const ClassID, ProgID: string); override;
private
{ Private declarations }
public
{ Public declarations }
end;
var
{
This example shows the implementation of a provider BeforeGetRecords
event handler and a RemoteDataModule UpdateRegistry method. The
complete project using this code example is in
Demos/DelphiWin32/VCLWin32/MIDAS/Pooler.
procedure TPooledRDM.DataSetProvider1BeforeGetRecords(Sender: TObject;
var OwnerData: OleVariant);
begin
try
Query1.Close;
Query1.SQL.Text := OwnerData[0];
if not VarIsNull(OwnerData[1]) and not VarIsEmpty(OwnerData[1]) then
begin
Query1.Open;
if not Query1.Locate(Query1.Fields[0].FieldName, OwnerData[1], []) then
raise Exception.Create('Record not found');
Query1.Next;
end;
finally
OwnerData := NULL;
end;
end;