[fpc-devel] Reading empty collection from stream
Michael Van Canneyt
michael at freepascal.org
Mon Sep 11 13:01:24 CEST 2006
On Thu, 7 Sep 2006, Marc Weustink wrote:
> Vincent Snijders wrote:
>> I am investigating Lazarus issue 7305. The TSynEdit class has a KeyStrokes
>> property of the type TSynEditKeyStrokes, which is a TCollection descendant.
>> The TSynEdit constructor fills the collection with some default items. If I
>> remove the items and stream the TSynEdit, the following line is shown in
>> the lfm:
>> Keystrokes = <>
>> If I read this lfm, I don't get a empty KeyStrokes collection, but one
>> filled with the default value.
>> I suspect the following lines in TReader.ReadCollection cause this
>> if not EndOfList then
>> Is this a bug or by design? How do I load an empty collection from a
>> stream, if the collection has a default value?
> Delphi has the same construction, which is IMO a design flaw.
> IMO when a collection is "default" is shouldn't be streamed, so there would
> be nothing written.
There is no way to know whether the collection is default or not,
since that would imply keeping a copy of the collection as it was
just after creation.
> I don't know why it is there, since when a "default" collection is written,
> all elements are written. So it never will be <>.
>> Note, if I remove the 'Keystrokes = <>' line from the lfm, I will get the
>> default collection too, so I wonder why there are two ways to get the
>> default collection.
> I propose to remove the "if not EndOfList then Collection.Clear;" line.
You may not, because then inherited form streaming will be broken:
a collection of "<>" means: don't touch, keep the collection of
the parent form.
More information about the fpc-devel