I have the following Delphi code:
destructor TXX_XXXX.Destroy;
var
i: Integer;
begin
if Assigned(Allocations) then
begin
for i:=0 to (Allocations.Count - 1) do
begin
try
TXX_ALOC(Allocations.Items[i]).Free;
except on Ex:Exception do
begin
OutputDebugString(PChar('Exception Error Message '+ Ex.Message));
end;
end;
end;
// Above code works well - no exception
try
FreeAndNil(Allocations); {Exception Here}
except on E:Exception do
begin
OutputDebugString(PChar('Exception in xxxxxxxxx.pas'+E.Message));
end;
end;
end;
inherited;
end;
Access violation at address 4003AB4 in module 'Vcl50.bpl'. Read of address 2980BFFC
I know the access violation usually caused by
- free some object which has been freed before
- use some object without initialization
But here before I do the free, I checked Allocations is assigned. If I discard the exception handling, my application will throw a something is wrong error. Allocations is a TObjectList, if it is an array - I will doubt I didn't assign a length to the array, but it is a TObjectList.
Thanks a lot!