1 2 {3 FreeAndNil(Object) is a good idea, because if you don't nil an object,4 just free it, and the object stays in scope, you'll get a dangling pointer.5 Object.Free will only check if the object is nil or not,6 NOT if it's valid or not!7 8 But what do we do if we use a third party component,9 which may or may not have freed another object???10 11 Here is SafeFree: 12 }13 14 procedure SafeFree(var O: TObject);
15 begin16 try//now do something - ANYTHING that will be caught by try17 //if the object is invalid18 O.FieldAddress('7351');
19 //By now we either have a valid object or we went to the except block.20 FreeAndNil(O);
21 except22 O := nil;
23 end;
24 end;
25 26 {27 In older versions of Delphi, you won't find FreeAndNil, but you can always use this:28 Object.Free;29 Object := nil;30 }31 32 Email Address: Support@HeuristicResearch.com