Recent

Author Topic: [Solved] Property NullDisplayText  (Read 2474 times)

sierdolg

  • New Member
  • *
  • Posts: 21
[Solved] Property NullDisplayText
« on: February 23, 2018, 12:02:44 pm »
Hello experts,

is there something equivalent to a .nulldisplaytext property, displayable in a database aware control to indicate that its value is not set in the resultset, like "n/a" instead of "".

[Which could also useful to display a hint to enter what sort of missing data ,-)]

An alternative idea might be to extend the Delphi compatible .DisplayFormat of a dataset's field whith its up to three components (positive, negative, zero value) to an optional fourth component (for NULL/EMPTY values).

Has anybody already found a nice solution for that purpose?
« Last Edit: February 26, 2018, 01:20:10 pm by sierdolg »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Property NullDisplayText
« Reply #1 on: February 23, 2018, 12:56:05 pm »
You can hook the event that gets the displaytext, and do whatever transformation you want.

The classic reason to do that is for memo fields that are typically not shown in grids. e.g.

Code: Pascal  [Select][+][-]
  1. procedure TSqlCreateFrm.defaultgettext(Sender: TField; var Textit: string;
  2.   DisplayText: Boolean);
  3. begin
  4.     if DisplayText then
  5.      Textit := Copy(sender.AsString, 1, 50) // in case for display text, only show part
  6.   else
  7.      Textit:=sender.AsString;
  8. end;

In the designer or in code set thegrid.ongettext to defaultgettext;

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: Property NullDisplayText
« Reply #2 on: February 23, 2018, 01:13:17 pm »
is there something equivalent to a .nulldisplaytext property, displayable in a database aware control to indicate that its value is not set in the resultset, like "n/a" instead of "".
For TEdit there is TEdit.TextHint which shows the text in grey when it is empty.

TDBEdit also has the TextHint but it isn't published. So I'm not sure it works for NULL.
You can try setting it in code.


sierdolg

  • New Member
  • *
  • Posts: 21
Re: Property NullDisplayText
« Reply #3 on: February 26, 2018, 01:18:54 pm »
Dear rvk,

this .TextHint property is and does _exactly_ what I was looking for.
(First and foremost it also automatically clears this hint on entering the field.) And works for the NULL value.

Thanks a lot!

(Supposably its name "hint" set me on the wrong track, as I thought of a hovering hint.)

Hence the only remaining small question might be why not to publish such a useful property to the object inspector ,-)

« Last Edit: February 26, 2018, 01:21:10 pm by sierdolg »

 

TinyPortal © 2005-2018