以前写的一个参考一下
unit SynthQryTrxDMObj;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComServ, ComObj, VCLCom, StdVcl, bdemts, DataBkr, DBClient,
MtsRdm, Mtx, SynthQryProv_TLB, Provider, DB, ADODB;
type
TSynthQryTrxDM = class(TMtsDataModule, ISynthQryTrxDM)
ADOC: TADOConnection;
SynthQuery: TADOQuery;
dspSynthQuery: TDataSetProvider;
RevenueOfQuery: TADOTable;
dspRevenueOfQuery: TDataSetProvider;
procedure MtsDataModuleCreate(Sender: TObject);
procedure dspSynthQueryBeforeGetRecords(Sender: TObject;
var OwnerData: OleVariant);
private
{ Private declarations }
protected
class procedure UpdateRegistry(Register: Boolean;
const ClassID, ProgID: string);
override;
public
{ Public declarations }
end;
implementation
uses reg, Variants;
{$R *.DFM}
class procedure TSynthQryTrxDM.UpdateRegistry(Register: Boolean;
const ClassID, ProgID: string);
begin
if Register then
begin
inherited UpdateRegistry(Register, ClassID, ProgID);
EnableSocketTransport(ClassID);
EnableWebTransport(ClassID);
end else
begin
DisableSocketTransport(ClassID);
DisableWebTransport(ClassID);
inherited UpdateRegistry(Register, ClassID, ProgID);
end;
end;
procedure TSynthQryTrxDM.MtsDataModuleCreate(Sender: TObject);
begin
ADOC.ConnectionString := reg.GetConnectionString;
end;
procedure TSynthQryTrxDM.dspSynthQueryBeforeGetRecords(Sender: TObject;
var OwnerData: OleVariant);
const EmptySQL = 'SELECT NULL';
begin
SynthQuery.Active := False;
SynthQuery.SQL.Clear;
if VarIsArray(OwnerData) then
begin
if OwnerData[0] = GUIDToString(LIBID_SynthQryProv) then
try
SynthQuery.SQL.Add(OwnerData[1]);
except
SynthQuery.SQL.Add(EmptySQL);
end
else
SynthQuery.SQL.Add(EmptySQL);
end
else
SynthQuery.SQL.Add(EmptySQL);
end;
initialization
TComponentFactory.Create(ComServer, TSynthQryTrxDM,
Class_SynthQryTrxDM, ciMultiInstance, tmApartment);
end.