regression, deserializing empty TCollection dont clear the current content anymore
Original Reporter info from Mantis: BBaz @basile.b
-
Reporter name:
Original Reporter info from Mantis: BBaz @basile.b
- Reporter name:
Description:
when you deserialize and empty TCollection from a textual stream ( possibly also binary stream),
the current content is not cleared, while it was in previous FCL versions (up to, included, 3.0.2).
Steps to reproduce:
run this program, the second assertionb should pass but fails:
---
{$Mode objfpc}{$H+}{$Assertions on}
program Project1;
uses Classes;
type
TItem = class(TCollectionItem)
public
fmember: integer;
published
property member: integer read fmember write fmember;
end;
TCol = class(TComponent)
strict private
fitems: TCollection;
procedure setItems(i: TCollection);
public
procedure loadFromString(const s: string);
constructor create(aOwner: TComponent); override;
destructor destroy; override;
published
property items: TCollection read fitems write setItems;
end;
procedure TCol.setItems(i: TCollection);
begin
fitems.Assign(i);
end;
procedure TCol.loadFromString(const s: string);
var
txt: TmemoryStream;
bin: TMemoryStream;
begin
txt := TMemoryStream.Create;
bin := TMemoryStream.Create;
try
txt.Write(s[1], length(s));
txt.Position:=0;
try
ObjectTextToBinary(txt, bin);
except
exit;
end;
bin.Position:=0;
bin.ReadComponent(self);
finally
bin.Free;
txt.Free;
end;
end;
constructor TCol.create(aOwner: TComponent);
begin
inherited create(aOwner);
fitems := TCollection.Create(TItem);
end;
destructor TCol.destroy;
begin
fItems.free;
inherited;
end;
var
c: TCol;
s: string;
begin
c := TCol.create(nil);
try
c.items.Add();
assert(c.items.count = 1); // OK
s := 'object TCol'#13'items=<>'#13'end';
c.loadFromString(s);
assert(c.items.count = 0); // NG
finally
c.free;
end;
end.
---
Mantis conversion info:
- Mantis ID: 37560
- Version: 3.2.0