X
xiaasp
Unregistered / Unconfirmed
GUEST, unregistred user!
源代码如下:
.........
TQueryThread=Class(TThread)
private
FCDSAuthors:TClientDataSet;
FCDSBooks:TClientDataSet;
FObjQuery:variant;
FAuthorsData:OleVariant;
FBooksData:OleVariant;
protected
procedure Execute;override;
procedure UpdateCDS;
public
constructor Create(CDS1,CDS2:TClientDataSet);
end;
.........
implementation
var
hMutex:THandle=0;
........
constructor TQueryThread.Create(CDS1,CDS2:TClientDataSet);
begin
FreeOnTerminate:=True;
FCDSAuthors:=CDS1;
FCDSBooks:=CDS2;
inherited Create(False);
end;
procedure TQueryThread.Execute;
begin
if WaitForSingleObject(hMutex,0)=WAIT_OBJECT_0 then
begin
try
FObjQuery:=CoXTQuery.CreateRemote('Xia');//此处报错
FObjQuery.GetAuthors_ForGUI('select * from authors',FAuthorsData);
FObjQuery.GetBooks_ForGUI('select * from Books',FBooksData);
Synchronize(UpdateCDS);
except
on Exceptiondo
showmessage('获取数据错误');
end;
ReleaseMutex(hMutex);
end;
end;
procedure TQueryThread.UpdateCDS ;
begin
FCDSAuthors.Data:=FAuthorsData;
FCDSBooks.Data:=FBooksData;
end;
设计该线程的目的是为了将COM+的建立和远程调用放在线程中,使得在COM+首次建立时客户端主程序不至于长时间动不了。
然后执行该线程:
TQueryThread.Create(CDSAuthors,CDSBooks);//参数是客户端两个ClientDataSet控件名
但报错:
project Project1.exe rasied exception class EOleSysError with message'标记没有引用存储',Process stopped.
请问是什么原因?
我知道一点在MIDAS中客户端在多线程中远程调用要Marshal接口,那么在COM+中这儿是不是也要Marshl接口?如果是,具体如何实现(需要代码,不是理论)?
备注:远程调用代码没有错误,如果以下代码不放在线程中可以执行成功:
FObjQuery:=CoXTQuery.CreateRemote('Xia');
FObjQuery.GetAuthors_ForGUI('select * from authors',FAuthorsData);
FObjQuery.GetBooks_ForGUI('select * from Books',FBooksData);
.........
TQueryThread=Class(TThread)
private
FCDSAuthors:TClientDataSet;
FCDSBooks:TClientDataSet;
FObjQuery:variant;
FAuthorsData:OleVariant;
FBooksData:OleVariant;
protected
procedure Execute;override;
procedure UpdateCDS;
public
constructor Create(CDS1,CDS2:TClientDataSet);
end;
.........
implementation
var
hMutex:THandle=0;
........
constructor TQueryThread.Create(CDS1,CDS2:TClientDataSet);
begin
FreeOnTerminate:=True;
FCDSAuthors:=CDS1;
FCDSBooks:=CDS2;
inherited Create(False);
end;
procedure TQueryThread.Execute;
begin
if WaitForSingleObject(hMutex,0)=WAIT_OBJECT_0 then
begin
try
FObjQuery:=CoXTQuery.CreateRemote('Xia');//此处报错
FObjQuery.GetAuthors_ForGUI('select * from authors',FAuthorsData);
FObjQuery.GetBooks_ForGUI('select * from Books',FBooksData);
Synchronize(UpdateCDS);
except
on Exceptiondo
showmessage('获取数据错误');
end;
ReleaseMutex(hMutex);
end;
end;
procedure TQueryThread.UpdateCDS ;
begin
FCDSAuthors.Data:=FAuthorsData;
FCDSBooks.Data:=FBooksData;
end;
设计该线程的目的是为了将COM+的建立和远程调用放在线程中,使得在COM+首次建立时客户端主程序不至于长时间动不了。
然后执行该线程:
TQueryThread.Create(CDSAuthors,CDSBooks);//参数是客户端两个ClientDataSet控件名
但报错:
project Project1.exe rasied exception class EOleSysError with message'标记没有引用存储',Process stopped.
请问是什么原因?
我知道一点在MIDAS中客户端在多线程中远程调用要Marshal接口,那么在COM+中这儿是不是也要Marshl接口?如果是,具体如何实现(需要代码,不是理论)?
备注:远程调用代码没有错误,如果以下代码不放在线程中可以执行成功:
FObjQuery:=CoXTQuery.CreateRemote('Xia');
FObjQuery.GetAuthors_ForGUI('select * from authors',FAuthorsData);
FObjQuery.GetBooks_ForGUI('select * from Books',FBooksData);