声明一全程信号量并作相应的处理
HSemaphore:THandle;
initialization
HSemaphore:=CreateSemaphore(nil,MAXOBJECTCOUNT,MAXOBJECTCOUNT,'');
^^^^^---对象个数阈值
TMyComponentFactory.Create(ComServer, TTest, Class_Test, ciMultiInstance,
^^--见后面 tmApartment);
finalization
CloseHandle(HSemaphore);
继承TComponentFactory, 改写CreateInstance
type
TMyComponentFactory = class(TComponentFactory, IClassFactory)
protected
function CreateInstance(const UnkOuter: IUnknown;
const IID: TGUID;
out Obj): HResult;
stdcall;
end;
function TMyComponentFactory.CreateInstance(const UnkOuter: IUnknown;
const IID: TGUID;
out Obj): HResult;
stdcall;
begin
if WaitForSingleObject(HSemaphore,INFINITE)=WAIT_OBJECT_0 then
Result:=inherited CreateInstance(UnkOuter, IID, Obj)
else
Result:=E_FAIL;
end;
并在你的远程数据模板的Destroy中释放信号量
type
TTest = class(TRemoteDataModule, ITest)
public
destructor Destroy;
override;
end;
destructor TTest.Destroy;
begin
inherited Destroy;
ReleaseSemaphore(HSemaphore,1,nil);
end;
这样就应该可以了, 没有