Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-02

TStringList.Put calls change even if value hasn't changed

6 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bart

When you do something like

  StringList1.Strings[Index] := Value

it calls TStringList.Put().

I would expect that if Value = Strings[Index] then nothing happens, and no Change or Changing are called.

Muttatis mutandis for PutObject.

Procedure TStringList.Put(Index: Integer; const S: string);
begin
  If Sorted then
    Error(SSortedListError,0);
  If (Index<0) or (INdex>=Fcount)  then
    Error (SListIndexError,Index);
//First check for   Flist^[Index].FString = S, and if so exit?
  Changing;
  Flist^[Index].FString:=S;
  Changed;
end;
Procedure TStringList.PutObject(Index: Integer; AObject: TObject);
begin
  If (Index<0) or (INdex>=Fcount)  then
    Error (SListIndexError,Index);
//First check for Flist^[Index].FObject equals AObject, and if so Exit?
  Changing;
  Flist^[Index].FObject:=AObject;
  Changed;
end;

Of course I might be horribly wrong.
Can someone elaborate on this?

Bart

Michael Van Canneyt
to Bart
Bart wrote 6 lines
When you do something like StringList1.Strings[Index] := Value it calls TStringList.Put(). I would expect that if Value = Strings[Index] then nothing happens, and no Change or Changing are called.

You expect wrong. No supposition is made whatsoever on the value. Every write in the list triggers a change.

This is how delphi implements it, and that is how we implemented it.

Michael.

Bart
to Michael Van Canneyt
Michael Van Canneyt wrote
You expect wrong. No supposition is made whatsoever on the value. Every write in the list triggers a change. This is how delphi implements it, and that is how we implemented it.

That's why I mentioned I might be horribly wrong.
So Delphi compatibility.

I think it's inconsitent with other components that have a OnChange. Generally this is only fired if something (text) "really" changed.

Current behaviour leads to many unneccesary calls to OnChange and OnChanging in a certain Lazarus LCL component (fixed it there).

Thanks for explaining.

Bart

Michael Van Canneyt
to Bart
Bart wrote 9 lines
On 2/10/13, Michael Van Canneyt wrote: > You expect wrong. No supposition is made whatsoever on the value. > Every write in the list triggers a change. > > This is how delphi implements it, and that is how we implemented it. That's why I mentioned I might be horribly wrong. So Delphi compatibility.

Yes.

I think it's inconsitent with other components that have a OnChange. Generally this is only fired if something (text) "really" changed.

There are many exceptions to that rule.

Current behaviour leads to many unneccesary calls to OnChange and OnChanging in a certain Lazarus LCL component (fixed it there).

I am aware of this.

But the impact of changing it is impossible to guess, so it is not subject to change.

Michael.

Bart
to Michael Van Canneyt
Michael Van Canneyt wrote 5 lines
I am aware of this. But the impact of changing it is impossible to guess, so it is not subject to change.

Which is fine by me.
I just wondered, and now I'm informed...
And with that new knowledge I can improve my code.

Thanks.

Bart

Michael Van Canneyt
to Bart
Bart wrote 11 lines
On 2/11/13, Michael Van Canneyt wrote: > I am aware of this. > > But the impact of changing it is impossible to guess, so it is not > subject to change. > Which is fine by me. I just wondered, and now I'm informed... And with that new knowledge I can improve my code.

Glad to be of help :-)

Michael.