I've noticed that it's possible to set the TextHint property on a TDBEdit in code (it's not visible in the Object Inspector), however it doesn't display, is there an easy way of making this work?
Asked
Active
Viewed 292 times
1
-
@Miamy The TextHint property displays within the Edit control when no value is present. `dbeSurname.TextHint := 'Surname'` – Alister Oct 22 '18 at 21:16
-
@Miamy: `Hint` <> `TextHint`. – MartynA Oct 22 '18 at 21:18
-
Runtime themes must be enabled, according to docs. – LU RD Oct 22 '18 at 21:47
-
I can confirm texthints work on dbedits with XE2. For whatever reason the control has to receive focus at least once though. – Sertac Akyuz Oct 22 '18 at 21:52
-
Does the _Visual Styles_ enabled? – Ilyes Oct 22 '18 at 22:21
-
@SertacAkyuz "*For whatever reason the control has to receive focus at least once though*" - that has not been my experience, and the underlying API ([`EM_SETCUEBANNER`](https://learn.microsoft.com/en-us/windows/desktop/controls/em-setcuebanner)) certainly does not require it. But I haven't tried it with `TDBEdit` specifically, though. Maybe there is a bug in `TDBEdit` that does not apply `EM_SETCUEBANNER` correctly. – Remy Lebeau Oct 22 '18 at 22:27
-
@RemyLebeau It seems like a bug, cause it's not working for me too (Delphi 10 Seattle). Even with `SendTextMessage(DBEdit1.Handle, EM_SETCUEBANNER, WPARAM(0), 'SomeValue');` – Ilyes Oct 22 '18 at 22:30
-
I've never had such a focus problem when using `EM_SETCUEBANNER` directly with standard `TEdit` controls. – Remy Lebeau Oct 22 '18 at 22:37
-
1@Remy - Implementation does not seem to have any problem, DBEdit or its ascendant TCustomMaskEdit does not override DoSetTextHint of TCustomEdit. There's no *focus once requirement* problem with a regular edit. *Edit:* Probably because the DBEdit is created *ReadOnly*. When ReadOnly, the regular edit does not show the texthint. – Sertac Akyuz Oct 22 '18 at 22:41
-
@SertacAkyuz ."*When ReadOnly, the regular edit does not show the texthint*" - correct, because that is how the OS implements it. Cue banners do not work on read-only or disabled controls. – Remy Lebeau Oct 22 '18 at 22:58
1 Answers
4
The following setup works in XE2. Drop a TClientDataSet
, TDataSource
, and 2 TDBEdit
controls on a Form, and make the OnCreate
event handler of the Form look like this:
procedure TForm1.FormCreate(Sender: TObject);
begin
DataSource1.DataSet := ClientDataSet1;
DBEdit1.DataSource := DataSource1;
DBEdit2.DataSource := DataSource1;
ClientDataSet1.FieldDefs.Add('First', ftString, 20);
ClientDataSet1.FieldDefs.Add('Last', ftString, 20);
ClientDataSet1.CreateDataSet;
ClientDataSet1.Open;
DBEdit1.DataField := ClientDataSet1.Fields[0].FieldName;
DBEdit1.TextHint := 'first name';
DBEdit2.DataField := ClientDataSet1.Fields[1].FieldName;
DBEdit2.TextHint := 'last name';
ClientDataSet1.Insert;
end;
One potential problem is the TDBEdit
s being read-only. For instance, remove the Insert()
call from the snippet and the edits will remain empty. This behavior is similar with regular edits, which is reasonable - when an edit control does not allow editing, there's no point in showing a hint about what the user should enter.

Remy Lebeau
- 555,201
- 31
- 458
- 770

Sertac Akyuz
- 54,131
- 4
- 102
- 169
-
This test application does indeed work in Berlin, I wonder what magic incantations I need to perform to get this working in my application. – Alister Oct 23 '18 at 01:03