>>Is it more efficient to store the value in a local boolean variable before
>>applying to several components?

Yes

>>Often it is more than 2 components I want enabled/disabled based on the
>>Options selection.  There can be 6 for example, which is why I was
>>interested to know the best way of coding it.

6 is not big enough. You need a profiler to tell you where the bottleneck
first.

Regards
Leigh

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Behalf Of Ross Levis
Sent: Friday, October 31, 2003 1:49 PM
To: Multiple recipients of list delphi
Subject: Re: [DUG]: Just wondering...


Hi Dennis (and others)

So I presume you are suggesting the more efficient way is to repeat the
itemindex = 1 expression.

Options is usually a radio group, but sometimes it's a checkbox and using
the checked property instead of itemindex = 1.

Often it is more than 2 components I want enabled/disabled based on the
Options selection.  There can be 6 for example, which is why I was
interested to know the best way of coding it.  Not that the speed difference
would be noticeable but if one is more efficient than the other then why not
use it from now on.

Is it more efficient to store the value in a local boolean variable before
applying to several components?

Regards,
Ross.

----- Original Message -----
From: "Dennis Chuah" <[EMAIL PROTECTED]>
To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]>
Sent: Friday, October 31, 2003 1:11 PM
Subject: Re: [DUG]: Just wondering...


>
> Actually, this is a misconception.  The compiler cannot fold the code
> because Option.ItemIndex accesses a property, which translates to a method
> call, and therefore can have side-effects.  (Yes folks, all property
> accesses are method calls, even if no accessor methods are defined and the
> property points directly at a variable.)  So, if the optimiser were to
fold
> the code, you would only get one method call instead of two!  The only
time
> when code is folder (and it is not even guaranteed), is when you directly
> access variables.
>
> ----- Original Message -----
> From: "Rohit Gupta" <[EMAIL PROTECTED]>
> To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]>
> Sent: Friday, October 31, 2003 12:07 PM
> Subject: Re: [DUG]: Just wondering...
>
>
> > First because the compiler should detect it and fodl the code.
> >
> > Second because it uses less cpu cycles.
> >
> > :-)
> >
> > I normally use a local variable to hold teh value with a name that
> > tells the world what it means.  Or
> >
> > if Option.ItemIndex = 1
> > then begin
> > end
> > else begin
> > end
> >
> > >
> > > Which of the following codeis the most efficient/fastest to execute?
> > >
> > > Label1.Enabled := Option.ItemIndex = 1;
> > > Label2.Enabled := Option.ItemIndex = 1;
> > >
> > > or
> > >
> > > Label1.Enabled := Option.ItemIndex = 1;
> > > Label2.Enabled := Label1.Enabled;
> > >
> > > Thanks,
> > > Ross Levis.

---------------------------------------------------------------------------
    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/


---------------------------------------------------------------------------
    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