三层架构多线程查询问题------同步不执行问题(100分)

  • 主题发起人 percychein
  • 开始时间
P

percychein

Unregistered / Unconfirmed
GUEST, unregistred user!
写了一个多线程访问多层数据库的程序,结果发现在同步的地方不能执行。代码如下:
unit uThread;
interface
uses
SConnect,Classes,Db,Variants,ComObj,DBClient,ActiveX,Midas,Provider;
type
test = class(TThread)
private
{ Private declarations }
protected
procedure Execute;
override;
procedure go;
public
Qry1 : TClientDataSet;
FStream: Pointer;
FNewData:OleVariant;
constructor Create(CDS: TClientDataSet);
end;

implementation
uses uPackInputModify;
{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure test.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end;
}
{ test }
procedure test.Execute;
var
OwnerData: OleVariant;
RecsOut: Integer;
Params:OleVariant;
Appserver:IAppserver;
const temp = 'select * from sajet.g_sn_status where work_order = ''511P06030026'' ' ;
begin
OleCheck(CoInitialize(nil));
try
OleCheck(CoGetInterfaceAndReleaseStream(IStream(FStream), IID_IAppServer,
Appserver));
FNewData :=
AppServer.AS_GetRecords (qry1.ProviderName,
-1,RecsOut,MetaDataOption,temp,Params,OwnerData);
Synchronize(go);------------程序在此处停止,线程也无法结束
finally
CoUninitialize;
end;
end;
constructor test.Create(CDS: TClientDataSet);
begin
FreeOnTerminate := True;
// G_sockConnection1 := G_sockConnection;
Qry1 := CDS;
OleCheck(CoMarshalInterThreadInterfaceInStream(
IID_IAppServer,
Qry1.AppServer,
IStream(FStream)));
inherited Create(False);
end ;
procedure test.go;
begin
qry1.AppendData(FNewData,True);
fCusSNModify.DataSource1.DataSet := qry1;
end;

end.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
820
SUNSTONE的Delphi笔记
S
顶部