[DUG] Related try..finally question

James Sugrue jamessugrue at xtra.co.nz
Fri Jul 21 14:43:09 NZST 2006


That's an interesting one. I guess you're talking about something like this?

Try
   Something := TSomething.Create(nil);
   X := TX.Create(blah); //for some reason crashes here
   Y := TY.Create();
Finally
   FreeAndNil(Something);
   FreeAndNil(X);
   FreeAndNil(y); //will throw exception (?) because was never created
End;

If so then you could just

If (something <> nil) then
   FreeAndNil(something);

??

(apologies for any coding errors, haven't done much Delphi recently)


-----Original Message-----
From: delphi-bounces at ns3.123.co.nz [mailto:delphi-bounces at ns3.123.co.nz] On
Behalf Of Conor Boyd
Sent: Friday, 21 July 2006 2:26 p.m.
To: NZ Borland Developers Group - Delphi List
Subject: [DUG] Related try..finally question

I'm getting the impression here that a lot of people only have a 1:1
relationship between try.finallys and procedures/functions?

Sounds a bit dangerous.

Should realistically be a try..finally for each object you instantiate
in a method.

Comments, anyone?

C.

_______________________________________________
Delphi mailing list
Delphi at ns3.123.co.nz
http://ns3.123.co.nz/mailman/listinfo/delphi



More information about the Delphi mailing list