(准备散分) 你了解DELPHI的COM机包装机制吗? 请过来看看 (0分)

  • 主题发起人 主题发起人 Jiams
  • 开始时间 开始时间
J

Jiams

Unregistered / Unconfirmed
GUEST, unregistred user!
现有一客户。主线程:
ClientDataSet-->Provier( 由 ISvr 导出的)
ClientDataSet.PackageRecord=25;
ClientDataSet.FetchOnDemand=False;
ClientDataSet.CommandText:='select * from AA';
ClientDataSet.Active:=true;
coMarshalInterThreadInterfaceInStream(IID_Svr,ISvr, stm);
查找时开一线程来下载数据,使主线程不致于出现不能重绘窗体而使窗体出空白一片
coInitializeEx(nil,Coint_Apartmentthread);
CoGetInterfaceAndReleaseStream(stm,IID_SVR, pv);
//vData:=pv.AS_GetRecords('provider',-1, iErrCount,ClientDataSet.CommandText, Params, OwnerData);
//ClientDataSet.Data:=vData;
ClientdataSet.Locate('bb','vv',[]);
// 此处会出错:为什么?
...................
coUninitialize()


 
Locate可能會有一些問題了,而且你的PackageRecord才是25條,你可試試別的方法來查找了。
 
有谁愿意交流一下多层数据结构的经验?(注意考虑安全性方面的问题) QQ:12220790
 
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.
代码:
 
分都沒有...
 
case coInitializeEx(nil, $2) of
 
后退
顶部