P E Schoen
2010-12-25 20:03:03 UTC
I was getting access violation errors with the following D4 code:
var tblOld,tblNew: TTable;
if tblNew = nil then //This causes an AV
tblNew := TTable.Create(fmReclData);
if tblNew <> nil then begin
tblNew.Active := False;
....
In the finally section I changed this to
finally
if assigned(tblNew) then begin
tblNew.Free;
tblNew := nil; end;
There is a compiler warning for the finally section that tblNew might not
have been initialized. In the first instance I simply removed the check for
nil. But what I found in the following link indicates that the two are
equivalent.
I suppose it is OK to omit a check for assignment in both cases of creating
the table and freeing it. However I suppose it might cause an AV for
tblNew.Free. Would it be better to assign a nil value to tblNew at the
beginning of the code? Is that any different than not assigning anything to
the variable at all?
Thanks, and Merry Christmas!
Paul
var tblOld,tblNew: TTable;
if tblNew = nil then //This causes an AV
tblNew := TTable.Create(fmReclData);
if tblNew <> nil then begin
tblNew.Active := False;
....
In the finally section I changed this to
finally
if assigned(tblNew) then begin
tblNew.Free;
tblNew := nil; end;
There is a compiler warning for the finally section that tblNew might not
have been initialized. In the first instance I simply removed the check for
nil. But what I found in the following link indicates that the two are
equivalent.
I suppose it is OK to omit a check for assignment in both cases of creating
the table and freeing it. However I suppose it might cause an AV for
tblNew.Free. Would it be better to assign a nil value to tblNew at the
beginning of the code? Is that any different than not assigning anything to
the variable at all?
Thanks, and Merry Christmas!
Paul