* TCollectionItem.Changed checks update counter of collection, resolves #13813

git-svn-id: trunk@13225 -
This commit is contained in:
florian 2009-06-01 16:09:56 +00:00
parent 38be92f20e
commit 398b5806b1
3 changed files with 54 additions and 2 deletions

1
.gitattributes vendored
View File

@ -9151,6 +9151,7 @@ tests/webtbs/tw1374.pp svneol=native#text/plain
tests/webtbs/tw1375.pp svneol=native#text/plain
tests/webtbs/tw1376.pp svneol=native#text/plain
tests/webtbs/tw13763.pp svneol=native#text/plain
tests/webtbs/tw13813.pp svneol=native#text/plain
tests/webtbs/tw13820.pp svneol=native#text/plain
tests/webtbs/tw1398.pp svneol=native#text/plain
tests/webtbs/tw1401.pp svneol=native#text/plain

View File

@ -42,7 +42,7 @@ end;
procedure TCollectionItem.Changed(AllItems: Boolean);
begin
If (FCollection<>Nil) then
If (FCollection<>Nil) and (FCollection.UpdateCount=0) then
begin
If AllItems then
FCollection.Update(Nil)
@ -123,7 +123,7 @@ end;
function TCollection.Owner: TPersistent;
begin
result:=getowner;
result:=getowner;
end;

51
tests/webtbs/tw13813.pp Normal file
View File

@ -0,0 +1,51 @@
program test_collection;
{$ifdef fpc}{$mode objfpc}{$h+}{$endif}
{$apptype console}
uses Classes;
type
titem = class(TCollectionItem)
public
procedure do_something;
end;
tcoll = class(TCollection)
public
procedure Update(Item: TCollectionItem); override;
end;
var
c: tcoll;
item: titem;
i: Integer;
update_counter: Integer;
procedure titem.do_something;
begin
Changed(False);
end;
procedure tcoll.Update(Item: TCollectionItem);
begin
Inc(update_counter);
inherited;
end;
begin
c := tcoll.Create(titem);
item := titem(c.Add);
update_counter := 0;
c.BeginUpdate;
try
for i := 0 to 9 do
item.do_something;
finally
c.EndUpdate;
end;
writeln('updates: ', update_counter);
c.Free;
if update_counter<>1 then
Halt(1);
end.