Can the TextHint property on a TDBEdit be made to work

336 Views Asked by At

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?

1

There are 1 best solutions below

1
On

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 TDBEdits 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.