我有一个存储一些对象的 TList。现在我有一个函数可以对该列表执行一些操作:
function SomeFunct(const AIndex: integer): IInterface
begin
if (AIndex > -1) and (AIndex < fMgr.Windows.Count ) then
begin
if (fMgr.Windows[AIndex] <> nil) then
begin
if not Supports(TForm(fMgr.Windows[AIndex]), IMyFormInterface, result) then
result:= nil;
end;
end
else
result:= nil;
end;
现在,真正奇怪的是,使用任何正确的索引访问 fMgr.Windows 会导致 EListError ......但是,如果我对其进行硬编码(例如,将 AIndex 替换为值 0 或 1)它可以正常工作。我尝试调试它,该函数被调用了两次,参数为 0 和 1(如预期的那样)。
当 AIndex = 0 时,评估 fMgr.Windows[AIndex] 会导致 $someAddress 处的 EListError,而评估 fMgr.Windws[0] - 返回正确的结果...
更奇怪的是,即使有 EListError,该函数也会返回正确的数据......并且不显示任何内容。只是关于关机时两个 EListError 内存泄漏的信息(使用 FastMM)
有什么想法可能是错的吗?!
在此先感谢