unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBClient, MConnect, StdCtrls, Grids, DBGrids,ComObj,ActiveX
,Provider,Midas;
type
TOpenThread = class(TThread)
private
FCDS: TClientDataSet;
FStream: Pointer;
FNewData:OleVariant;
protected
procedure Execute;
override;
procedure UpdateCDS;
public
constructor Create(CDS: TClientDataSet);
end;
TForm1 = class(TForm)
DCOMConnection1: TDCOMConnection;
ClientDataSet1: TClientDataSet;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TOpenThread }
constructor TOpenThread.Create(CDS: TClientDataSet);
begin
FreeOnTerminate := True;
FCDS := CDS;
OleCheck(CoMarshalInterThreadInterfaceInStream(
IID_IAppServer,
FCDS.AppServer,
IStream(FStream)));
inherited Create(False);
end;
procedure TOpenThread.Execute;
var
OwnerData: OleVariant;
RecsOut: Integer;
Params:OleVariant;
Appserver:IAppserver;
begin
OleCheck(CoInitialize(nil));
try
OleCheck(CoGetInterfaceAndReleaseStream(IStream(FStream), IID_IAppServer,
Appserver));
FNewData :=
AppServer.AS_GetRecords (FCDS.ProviderName,
-1,RecsOut,MetaDataOption,'',Params,OwnerData);
Synchronize(UpdateCDS);
finally
CoUninitialize;
end;
end;
procedure TOpenThread.UpdateCDS;
begin
FCDS.AppendData(FNewData,True);
Form1.DataSource1.DataSet:=FCDS;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
TOpenThread.Create(ClientDataSet1);
end;
end.
delphi7下成功运行,delphi5下把uses中的Variants去掉