> Just wondering, for a caption that doesn't change very oftern which in
> more efficient.
> 
> StateLabel.caption := 'Running';
> 
> OR
> 
> IF StateLabel.Caption <> 'Running' then
>        StateLabel.Caption := 'Running';

There are 2 sides to this...

1. The cost of the assignment versus the cost of the test

    String comparison are as far as comparisons go, pretty computationally heavy
    but on case-sensitive short string-lengths it is still likely that the cost of 
side-effects
    like redrawing the screen are more expensive than the comparison itself - Generally
    it's nice to test first (however see 2)...

2. The implementation of .Caption...
    .Caption is a property of your control, it is likely that the internal storage of 
this property
    is implemented in a SetCaption procedure like

    procedure TTheComponent.SetCaption(const Value :String);
    begin
        if Value<>FCaption then begin
            FCaption := Value;
            CaptionChanged;
        end;
    end;

    This allows side-effects like redraws and such... But note it protects against 
subsequent
    'Change' events being triggered if the newcaption matches the old caption...

IMHO with todays memory-scales your mind should always be on functionality, stability
and performance not minor byte-trimming with the source-code...  Selection of the right
algorithm for the job should be enough...

--
Aaron@home


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to