这是李维那本术中的,程序测试代码如下,供参考:(在D6下通过)
---------
unit Unit2;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
Windows, Messages, SysUtils, Classes, ComServ, ComObj, VCLCom, DataBkr,
DBClient, Project1_TLB, StdVcl, Provider, DB, ADODB,Variants;
type
Tserver_x = class(TRemoteDataModule, Iserver_x)
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
DataSetProvider1: TDataSetProvider;
procedure DataSetProvider1GetData(Sender: TObject;
DataSet: TCustomClientDataSet);
procedure DataSetProvider1AfterGetRecords(Sender: TObject;
var OwnerData: OleVariant);
function DataSetProvider1DataRequest(Sender: TObject;
Input: OleVariant): OleVariant;
private
{ Private declarations }
protected
class procedure UpdateRegistry(Register: Boolean; const ClassID, ProgID: string); override;
procedure GetAllTables(var vTables: OleVariant); safecall;
public
{ Public declarations }
end;
implementation
uses Unit1;
{$R *.DFM}
class procedure Tserver_x.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 Tserver_x.GetAllTables(var vTables: OleVariant);
var //-----------------这是你的程序的地方--------------------
tbList:TstringList;
iCount:integer;
begin
try
tbList:=TstringList.Create;
ADOConnection1.GetTableNames(tbList);
vTables:=VarArrayCreate([0,tbList.count-1],varVariant);
for icount:=0 to tbList.Count-1 do
begin
vTables[iCount]:=tbList.Strings[icount];
end;
finally
tbList.Free;
end;
end;
procedure Tserver_x.DataSetProvider1GetData(Sender: TObject;
DataSet: TCustomClientDataSet);
begin
if form1.label1.caption='EDUCAST_SERVER' then
form1.label1.caption:='SERVER'
else form1.label1.caption:='EDUCAST_SERVER';
end;
procedure Tserver_x.DataSetProvider1AfterGetRecords(Sender: TObject;
var OwnerData: OleVariant);
begin
if form1.label1.caption='EDUCAST_SERVER' then
form1.label2.Caption:='EDUCAST_SERVER';
if form1.label1.caption='SERVER' then
form1.label2.caption:='SERVER' ;
end;
function Tserver_x.DataSetProvider1DataRequest(Sender: TObject;
Input: OleVariant): OleVariant;
var iRecords:integer;
begin
{ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add(input);
ADOQuery1.Open; }
form1.label3.caption:=input ;
// Result:= DataSetProvider1.GetRecords(0,0,0);
//DataSetProvider1.reset(true);
//Result:=DataSetProvider1.GetRecords( 10,iRecords);;
//:=DataSetProvider1.GetRecords( 10,10);
end;
initialization
TComponentFactory.Create(ComServer, Tserver_x,
Class_server_x, ciMultiInstance, tmApartment);
end.