J
Julian2082
Unregistered / Unconfirmed
GUEST, unregistred user!
最近看到了这样的代码,看起来是在客护端实现了多线程,是不是按他的做法就可以在服务器端再建立一个独立的APARTMENT线程,实现所谓的多线程呢?有点困惑,望各位高手指教!
---------------------------------------
在Midas客户端用线程读取数据包
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;
fnewdatalevariant;
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;
paramslevariant;
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.