我有一個名爲ISupport的接口,用於提供技術支持信息。如何發現具體的類對象已經在TInterfaceList中?
ISupport = Interface(IInterface)
procedure AddReport(const Report: TStrings);
End;
每個具有用於支持實現該接口相關的信息,並在構造函數調用類:使用的
procedure TySupport.RegisterSupport(Support: ISupport);
begin
if FInterfaceList.IndexOf(Support) = -1 then
FInterfaceList.Add(Support);
end;
實施例(部分):
TyConfig = class(TInterfacedObject, ISupport)
private
procedure AddReport(const Report: TStrings);
public
constructor Create;
end;
constructor TyConfig.Create;
begin
if Assigned(ySupport) then
ySupport.RegisterSupport(Self);
end;
上的代碼後來我可以查看列表並調用AddReport。
我的問題是,有一個類,這個TyConfig,它被多次實例化,它會報告的信息是完全一樣的。 FInterfaceList.IndexOf只避免添加相同的接口。
我想避免來自TyConfig的ISupport獲得多次註冊。
相關信息[如何在Delphi中將接口轉換爲對象](http://stackoverflow.com/q/4138211/1699210) – bummi