unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBClient, MConnect, SConnect, StdCtrls, ActiveX, stgserver_TLB,
VCLCom;
type
TForm1 = class(TForm)
SocketConnection1: TSocketConnection;
cds: TClientDataSet;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TmThread = class(TThread)
private
FIobj: IStgRDM;
Fcds: TClientDataSet;
procedure Execute;
overload;
procedure Synchronize(Method: TThreadMethod);
overload;
public
constructor Create(CreateSuspended: Boolean;
var stm: IStream;
cds: TClientDataSet);
proceduredo
Terminate;
overload;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
stm: IStream;
iobj: IStgRDM;
unk: IInterface;
begin
cds.PacketRecords := 25;
cds.FetchOnDemand := False;
cds.CommandText := 'SELECT * FROM TIn';
cds.Active := true;
case coInitializeEx(nil, $3) of
S_OK: Caption := 'The COM library was initialized successfully on the calling thread.';
S_FALSE: Caption := ' The COM library is already initialized on the calling thread.';
RPC_E_CHANGED_MODE: Caption := 'A previous call to CoInitializeEx specified a different concurrency model for the calling thread, or the thread that called CoInitializeEx currently belongs to the neutral threaded apartment.';
end;
Caption := format('%d', [GetLastError]);
SetLastError(0);
unk := IStgRDM(cds.AppServer);
//下面这个函数调用就有问题了。stm返回是nil,返回结果不在case里
case coMarshalInterThreadInterfaceInStream(IID_IStgRDM, unk, stm) of
S_OK: Caption := 'Output stream contains marshalled interface.';
E_OUTOFMEMORY: Caption := 'There was not enough memory to complete the call.';
E_INVALIDARG: Caption := 'One or more arguments are invalid.';
end;
//查找时开一线程来下载数据,使主线程不致于出现不能重绘窗体而使窗体出空白一片
Caption := format('%d', [GetLastError]);
case CoGetInterfaceAndReleaseStream(stm, IID_IStgRDM, iobj) of
S_OK: Caption := 'Indicates the output interface was unmarshaled and the stream was released.';
E_INVALIDARG: Caption := 'Indicates that input arguments are invalid.';
end;
//vData:=pv.AS_GetRecords('provider',-1, iErrCount,ClientDataSet.CommandText, Params, OwnerData);
//ClientDataSet.Data:=vData;
//iobj.CallService(1, VarEmpty);
cds.Locate('In_num', VarArrayof([2]), []);
// 此处会出错:为什么?
//...................
coUninitialize();
end;
{ TmThread }
constructor TmThread.Create(CreateSuspended: Boolean;
var stm: IStream;
cds: TClientDataSet);
begin
inherited Create(CreateSuspended);
coInitializeEx(nil, $2);
CoGetInterfaceAndReleaseStream(stm,IID_IStgRDM, Fiobj);
end;
procedure TmThread.DoTerminate;
begin
inherited;
coUninitialize();
end;
procedure TmThread.Execute;
begin
Fcds.Locate('In_num', VarArrayof([2]), []);
end;
procedure TmThread.Synchronize(Method: TThreadMethod);
begin
inherited;
end;
end.