Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-06

Store empty string property in *.lfm

8 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

theo

Hello

Is it possible to store an empty string property?

The property is getting a default value a creation time (GetUserDir), If the user enters an empty string to the obj. insp. it is shown as empty but still has the value it got at creation time when run.

I've tried things like:
 property Directory: string read FDirectory write SetDirectory stored
True nodefault;

but it doesn't work. Empty String is never stored it seems.

Am I missing sth.?

Thanks
Theo

Reply by email

Mattias Gaertner
to theo
Show quoted text 15 lines
Hello Is it possible to store an empty string property? The property is getting a default value a creation time (GetUserDir), If the user enters an empty string to the obj. insp. it is shown as empty but still has the value it got at creation time when run. I've tried things like: property Directory: string read FDirectory write SetDirectory stored True nodefault; but it doesn't work. Empty String is never stored it seems. Am I missing sth.?

String properties always have as default value the empty string. But you can define a stored procedure.
See the TControl.Caption property.

Mattias

Reply by email

theo
to Mattias Gaertner

Thanks for your answer Matthias

String properties always have as default value the empty string. But you can define a stored procedure. See the TControl.Caption property.

I don't get what you mean. There I read:

    property Caption: TCaption read GetText write SetText stored
IsCaptionStored;

where afaics "IsCaptionStored" determines whether or not to store the Caption value.
But I simply want it always stored, even when empty.

Since it doesn't seem to work with empty string, I use a workaround which does the job for me:

procedure TThumbControl.SetDirectory(const AValue: UTF8String);
begin
  if AValue='' then fDirectory:='none' else fDirectory := AValue;
  if (fDirectory  'none') and (fDirectory  '') then
     if DirectoryExistsUTF8(AValue) then
     begin

Thank you
Best regards
Theo

Reply by email

Luiz Americo Pereira Camara
to theo: Hello Is it possible to store an empty string property? The property is getting a default…
theo wrote 15 lines
Hello Is it possible to store an empty string property? The property is getting a default value a creation time (GetUserDir), If the user enters an empty string to the obj. insp. it is shown as empty but still has the value it got at creation time when run. I've tried things like: property Directory: string read FDirectory write SetDirectory stored True nodefault; but it doesn't work. Empty String is never stored it seems. Am I missing sth.?

I've got same problem with VTV:
http://thread.gmane.org/gmane.comp.ide.lazarus.general/38378

See TCustomVirtualStringTree.Create in VitualTrees at lazarus-ccr for a solution

Luiz

Reply by email

Mattias Gaertner
to theo: Thanks for your answer Matthias I don't get what you mean. There I read: property…
Show quoted text 16 lines
Thanks for your answer Matthias > String properties always have as default value the empty string. > But you can define a stored procedure. > See the TControl.Caption property. I don't get what you mean. There I read: property Caption: TCaption read GetText write SetText stored IsCaptionStored; where afaics "IsCaptionStored" determines whether or not to store the Caption value. But I simply want it always stored, even when empty.

TWriter does not support that directly.
But you can do something like this:

procedure TThumbControl.SetDirectory(const AValue: UTF8String);
begin
  if AValue=fDirectory then exit;
  if csLoading in ComponentState then fDirectoryLoaded:=true;
  ...
end;
procedure TThumbControl.Loaded;
begin
  if not fDirectoryLoaded then fDirectory:='';
  fDirectoryLoaded:=false;
end;

Mattias

Reply by email

theo
to Mattias Gaertner

Thanks for your suggestions.

TWriter does not support that directly. But you can do something like this:

Yes, this is probably cleaner than my workaround with "none". But it needs one extra boolean field, and the "none" solution should be safe too. (Afaik there is no system where "none" without slashes is a valid absolute path).

Thank you Mattias.

Reply by email

Hans-Peter Diettrich
to theo: Thanks for your answer Matthias I don't get what you mean. There I read: property…
Show quoted text 15 lines
Thanks for your answer Matthias > String properties always have as default value the empty string. > But you can define a stored procedure. > See the TControl.Caption property. I don't get what you mean. There I read: property Caption: TCaption read GetText write SetText stored IsCaptionStored; where afaics "IsCaptionStored" determines whether or not to store the Caption value. But I simply want it always stored, even when empty.

AFAIR there exist problems with Text and Caption, which are treated together (exchangably or as fallbacks) by the default handlers. I don't see a reason for that strange behaviour. So the order of setting Text and Caption may be important, what's impossible to achieve in a streamed environment (using lfm files).

DoDi

Reply by email

Hans-Peter Diettrich
to theo: Thanks for your suggestions. Yes, this is probably cleaner than my workaround with "none".
Show quoted text 5 lines
Yes, this is probably cleaner than my workaround with "none". But it needs one extra boolean field, and the "none" solution should be safe too. (Afaik there is no system where "none" without slashes is a valid absolute path).

I typically use '<none>' to signal invalid entries, easily recognizable by the first character. A non-visual solution were e.g. a #0, that should be an illegal value in most cases, but still is a non-empty string.

DoDi

Reply by email