2

What is the reason for this surprising behaviour, that seems to have started after I upgraded Delphi from XE2 to 10.4.2, namely that empty string property values get stored to the .DFM file?

Empty string is supposed to be a built-in automatic default, i.e. not stored, for properties.

This happens for string properties named Text, in two components that derive from TWinControl (one directly, the other via TCustomEdit). Could it be because TWinControl derives from TControl, which also has a property called Text, but of type TCaption instead of type string? That was the same in XE2, but maybe "properties that hide other properties" are treated differently now in 10.4 compared to back then?

I could solve the sprinkling of unnecessary Text = '' in my .DFM files by addding a stored directive + a function – but I think I shouldn't really have to, should I?

property Text: string read GetText write SetText stored IsTextStored;

function TMyComponent.IsTextStored: Boolean;
begin
  Result := Text <> '';
end;
Matthias B
  • 404
  • 4
  • 11
  • 2
    You are correct that empty strings are not supposed to be stored in a DFM by default. If this is happening now, it is a regression that needs to be [reported to Embarcadero](https://quality.embarcadero.com). – Remy Lebeau Apr 11 '21 at 09:46
  • I can see this kind of behavior in XE4 (I don't have XE2 installed to verify behavior there) but for me just declaring published property as property Text; works without storing empty string. – Dalija Prasnikar Apr 11 '21 at 09:57
  • 3
    I have been made aware that this has been reported in https://quality.embarcadero.com/browse/RSP-26600, but dismissed. It is clear to me now that this happens because my property Text hides an ancestor's property Text, and property hiding is supposedly not an official feature and this construct should not be used. Implementation details surrounding DFM property writing has changed and therefore this surfaces now, but it really should never have worked. This is my current understanding of the case. – Matthias B Apr 11 '21 at 15:14

0 Answers0