David

> Neven's very similar suggestion which
> had one extra unnecessary line setting StringList1 to nil (which may also
> have the undesirable consequence of raising a hint/warning).

Hey but it had cadence, 3, 3 ,3

You are right, Though this may all be a bit academic because I
would also suggest that should you be nesting some 3+ levels of
create free then you probably should have fallen of the oo log and
should evelauate if you should be defining a class to encapsulate
all this and we don't have tyr finallys in constuctors

In practice I'd seldom get past 2, usually and object and a stream

Neven

----- Original Message ----- 
From: "David Brennan" <[EMAIL PROTECTED]>
To: "NZ Borland Developers Group - Delphi List" <[EMAIL PROTECTED]>
Sent: Thursday, March 04, 2004 11:42 PM
Subject: RE: [DUG] try..finally : Which way is best?


> Not only is there nothing technically wrong with Paul Needham's suggestion
> (ie...
>
> > issues := nil;
> > terrorists := nil;
> > changes := TStringList.create;
> > try
> >   issues := TIssuesList.create;
> >   terrorists := THardToFind.create;
>
> ...) but it also won't create any compiler warnings if you follow that
> formula - because there is nothing to warn about.
>
> While it does have two more lines of code than the potentially unsafe
> example that Nahum kicked this thread off with, it is still shorter than
> every other safe solution that I know of. For example it is shorter than
> nested try's and it is shorter than Neven's very similar suggestion which
> had one extra unnecessary line setting StringList1 to nil (which may also
> have the undesirable consequence of raising a hint/warning).
>
> Cheers,
> David Brennan.
> DB Solutions Ltd.
>
> >
> > re paul's suggestion.. while technically theres nothing wrong
> > with it, it'll add a
> > couple of (innocent) compiler warnings that might obscure
> > something more relevent.
> > (unless you implement a Nil() procedure..). plus you're adding
> > more lines of code to
> > maintain etc.. (minor point)
> >
> > issues := nil;
> > terrorists := nil;
> > changes := TStringList.create;
> > try
> >   issues := TIssuesList.create;
> >   terrorists := THardToFind.create;
> >
> > personally i'd like a switch so that delphi initialises local
> > vars.. but thats just
> > me :-)
> >
> > > is the following code ok? or should I give each it's own try..finally?
> > >
> > > --
> > >
> > > changes := TStringList.create;
> > > issues := TIssuesList.create;
> > > terrorists := THardToFind.create;
> > > try
> > >
> > > // stuff is done, planes flown.  That type of things.
> > >
> > > finally
> > >   terrorists.free;
> > >   issues.free;
> > >   changes.free;
> > > end;
> > >
> >
>
> _______________________________________________
> Delphi mailing list
> [EMAIL PROTECTED]
> http://ns3.123.co.nz/mailman/listinfo/delphi
>
>
>

_______________________________________________
Delphi mailing list
[EMAIL PROTECTED]
http://ns3.123.co.nz/mailman/listinfo/delphi

Reply via email to