mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-16 14:20:05 +02:00
* TCollectionItem.Changed checks update counter of collection, resolves #13813
git-svn-id: trunk@13225 -
This commit is contained in:
parent
38be92f20e
commit
398b5806b1
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -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
|
||||
|
@ -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
51
tests/webtbs/tw13813.pp
Normal 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.
|
Loading…
Reference in New Issue
Block a user