I have a TList which stores some objects. Now I have a function which does some operations on that list:
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;
now, what is really strange is that accessing fMgr.Windows with any proper index causes EListError... However if i hard-code it (in example, replace AIndex with value 0 or 1) it works fine. I tried debugging it, the function gets called twice, with arguments 0 and 1 (as supposed).
while AIndex = 0, evaluating fMgr.Windows[AIndex] results in EListError at $someAddress, while evaluating fMgr.Windws[0] instead - returns proper results ...
what is even more strange, even though there is an EListError, the function returns proper data ... and doesn't show anything. Just info on two EListError memory leaks on shutdown (using FastMM)
any ideas what could be wrong?!
Thanks in advance michal
I think you are just confusing the debugger in some way. Sometimes "clean", leak free code seems to generate a memory leak if there is a watch looking at a property, and evaluating that watch causes an exception. These aren't displayed to to the IDE they are handled by the debugger.
A case where this may happen is if you have a debugger showing fMgr.Windows[AIndex] before Aindex is intialised, or a watch on fMgr.Windows[0] before there are any items in the list.