【发布时间】:2010-03-21 10:10:18
【问题描述】:
我有以下代码:
for i := 0 to FControlList.Count - 1 do
if Supports(IMyControl(FControlList[i]), IMyControlEx) then
begin
MyControlEx := IMyControl(FControlList[i]) as IMyControlEx;
MyControlEx.DoYourMagic(Self, SomeData);
end;
此代码在我的应用程序执行期间被多次调用,但在某些特定情况下,它在 Supports() 方法中失败。更具体地说 - 它似乎属于 Supports() 方法中的 QueryInterface() 调用。
我检查了 FControlList 不是 nil 并且 FControlList[i] 不是 nil 并且它仍然会发生。
任何想法将不胜感激!!!
【问题讨论】:
-
您能否在 Supports 通话中移除对 IMyControl 的演员表?什么是 FControlList,一个 IInterfaceList?
-
还要注意,TControl 可以有自己的生命周期管理,即使它们是 TInterfacedPersistent 的子类,它们也不使用引用计数。见stackoverflow.com/questions/2182612
-
只是因为 TInterfacedPersistent 不使用引用计数。否则使用 TInterfacedObject。
-
支持需要为接口定义一个 GUID,我假设你已经为 IMyControlEx 这样做了。
标签: delphi access-violation queryinterface