Browse Source

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

git-svn-id: trunk@13225 -
florian 16 years ago
parent
commit
398b5806b1
3 changed files with 54 additions and 2 deletions
  1. 1 0
      .gitattributes
  2. 2 2
      rtl/objpas/classes/collect.inc
  3. 51 0
      tests/webtbs/tw13813.pp

+ 1 - 0
.gitattributes

@@ -9151,6 +9151,7 @@ tests/webtbs/tw1374.pp svneol=native#text/plain
 tests/webtbs/tw1375.pp svneol=native#text/plain
 tests/webtbs/tw1375.pp svneol=native#text/plain
 tests/webtbs/tw1376.pp svneol=native#text/plain
 tests/webtbs/tw1376.pp svneol=native#text/plain
 tests/webtbs/tw13763.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/tw13820.pp svneol=native#text/plain
 tests/webtbs/tw1398.pp svneol=native#text/plain
 tests/webtbs/tw1398.pp svneol=native#text/plain
 tests/webtbs/tw1401.pp svneol=native#text/plain
 tests/webtbs/tw1401.pp svneol=native#text/plain

+ 2 - 2
rtl/objpas/classes/collect.inc

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

+ 51 - 0
tests/webtbs/tw13813.pp

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