View Issue Details

IDProjectCategoryView StatusLast Update
0020166FPCRTLpublic2014-07-03 07:54
ReporterHert Vanz Assigned ToMichael Van Canneyt  
Status resolvedResolutionno change required 
Product Version2.5.1 
Summary0020166: TWriter doesn't stream empty value
DescriptionBy default, the TWriter class is not streaming properties which match the default value.

For instance; I create an object with a single string property and load it from a previously saves stream that contains a value in the string property. This works fine and my object now contains that value. Then subsequently, for this same object, I now load from another stream but this time the stream has an object with an empty string value. This string value was not written out to the stream because the TWriter thinks that an empty string value shouldn't have to be written. So after this second load, my object still contains the value of the first load, simply because the TReader didn't find (hence load) this property in the stream.

I know that this is by design, but would like to start a discussion to have this behavior changed. Delphi7 for instance writes empty strings to the output streams which is to be expected as an empty string is also a value. This doen't only apply to strings but any type... a 0 integer is also a value; a null variant is also a value.

In short I'd like to either have the default checking removed in TWriter.WriteProperty or have a setting for a TWriter where I can tell it to not check default values.
TagsNo tags attached.
Fixed in Revision
Attached Files


Jonas Maebe

2011-09-06 16:34

manager   ~0051513

Isn't the problem rather that properties not present in the stream aren't initialized to their default value?

Hert Vanz

2011-09-06 17:31

reporter   ~0051515

Oh no, that isn't a problem at all. The problem is that empty values aren't written to the stream and as a result not being loaded. A property could well get a default string value in the constructor and when emptied the empty property would have to be written so that on load of the stream the value is also set to the stored empty value.

Anton Kavalenka

2014-07-02 12:40

reporter   ~0076019

Last edited: 2014-07-02 12:41

View 2 revisions

Writer stores exactly as designed - vaString or va_String with zero length.
MB problem in IsStoredProp

But is seems all right there:
if property is publishead and read/write either directly or via getter/setter and isStored method permits - data will be written.

Michael Van Canneyt

2014-07-03 07:54

administrator   ~0076029

This is normal behaviour and as-designed.
Values equal to the default value are never written to the stream, that is why the concept of default value exists. For strings, the (implicit) default value is the empty string.

If you want a value to be written regardless, you must append the nodefault modifier to the property definition, this will cause TWriter to ignore default values.

Issue History

Date Modified Username Field Change
2011-09-06 12:05 Hert Vanz New Issue
2011-09-06 16:34 Jonas Maebe Note Added: 0051513
2011-09-06 17:31 Hert Vanz Note Added: 0051515
2014-07-02 12:40 Anton Kavalenka Note Added: 0076019
2014-07-02 12:41 Anton Kavalenka Note Edited: 0076019 View Revisions
2014-07-02 19:20 Jonas Maebe Assigned To => Michael Van Canneyt
2014-07-02 19:20 Jonas Maebe Status new => assigned
2014-07-03 07:54 Michael Van Canneyt Note Added: 0076029
2014-07-03 07:54 Michael Van Canneyt Status assigned => resolved
2014-07-03 07:54 Michael Van Canneyt Resolution open => no change required