Neven asked:

> If you are following a trail of properties, ie
> Datasource.DataSet.Connection
> is it be to test for assignment/nil a each step or
> just try except it?
>
> ie
>   if (Datasource <> nil) and
>      (Datasource.DataSet <> nil) and
>      (Datasource.DataSet.Connection <> nil)
>   then Result := Datasource.DataSet.Connection
>   else Result := nil;
> or
>
> try
>   Result := Datasource.DataSet.Connection
> except
>   Result := nil
> end;

>From an efficiency point of view, setting up and collapsing exception frame
is not free.

Whether it's cheaper than the code to test all the pointers against nil
would depend on how many you were testing. I haven't examined the generated
code but I would not be suprised if it took quite a few pointer tests before
the exception handling overhead was a net win.

Now, if the exception is actually _fired_, you'd be paying lots of cycles so
I wouldn't use this idiom where you expect Result to be nil very often.
Exception processing itself is not cheap - it should only really be used for
catching rare cases  (hence the name exception I suppose :-)

The efficiency concerns would put me off using this idiom, but from a style
point of view, I'd say it's a matter of personal preference.

TTFN,
  Paul.


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

Reply via email to