不好意思, 偶在苏州出差,这里上网慢的要命, 这个月几乎没上来几次.
提供一点思路:
unit MyComServer;
interface
uses ComObj, ComServ;
TMyComserver = class(TComServer)
private
public
function CountObject(Created: Boolean): Integer; override;
function CountFactory(Created: Boolean): Integer; override;
end;
var
MyComServer: TMyComServer;
implememtation
function TMyComserver.CountObject(Created: Boolean): Integer;
begin
Result := Inherited CountObject(Created);
end;
function TMyComserver.CountFactory(Created: Boolean): Integer;
begin
Result := Inherited CountFactory(Created);
end;
initialization
begin
MyComServer := TMyComServer.Create;
end;
finalization
begin
MyComServer.Free; //注意: 这里可能需要作一些处理
end;
///////////////////////////////////////////////////////////////////////////////////
// 在你的服务器单元里 把原来的ComServer替换掉, 但是保留对它的Uses
//
///////////////////////////////////////////////////////////////////////////////////
/////////////////
TAutoObjectFactory.Create(MyComServer, TYourServerApp, YourCalssID, ciSingleInstance);
.....
TYourServer.Button1Click(Sender: TObject);
begin
//This only count object to 0;
while MyComServer.CountObject(False)>0 do
;
while MyComObject.CountFactory(False)>0 do
;
//You need trace TAutoObject create, and store all auto object in some place.
//and free them here. OR some thing unexpected maybe happened.
end;