Delphi 7 question. I'm working with a form that has many databound controls (changing this is not an option). I have a TDBEDIT control bound to a TStringField (which has a EditMask property). I know I can use this EditMask to force the control to validate its input, but what I want to know is if I can populate the field directly with the raw value and have the control display it according to the EditMask?
I want to populate the field with a 16 digit number, but I want it displayed as 4 lots of 4 digits (ie. 9999 9999 9999 9999).
If I do ...
dbedtABCNumber.DataSource.DataSet.Edit;
dbedtABCNumber.Field.Value := '1234567812345678';
I only get the first 4 digits displayed.
I hope there's someone out there who's more familiar with the intracacies of old databound controls.
You can use the TField.OnGetText event or TNumericField.DisplayFormat property to modify how the text is being displayed.
Since you have a TStringField holding numbers, you have two choices:
TNumericField
and the DisplayFormat
propertyOnGetText
event and do your own string formattingEdit:
Sam used this approach:
I implemented OnSetText
and OnGetText
event handlers. I already had the Edit Mask
9999 9999 9999 9999;1;_
so the OnSetText
was just
TStringField(Sender).Value := Trim(Text);
and OnGetText
was just
sValue := TStringField(Sender).Value;
Text := Format('%s %s %s %s', [Copy(sValue, 1, 4), Copy(sValue, 5, 4), Copy(sValue, 9, 4), Copy(sValue, 13, 4)]);
It works fine. Thanks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With