Tfield EditMask lazarus / 31-LCL ---------------------------------------------------------------------- Walmir · 2014-08-01 19:36 Hi, I need to use various masks with string fields. Some of them are fairly complex, like 00.000.000/0000-00;0;_ For some reason, I only can see the masks when I edit the field. They disappear as soon as the focus leaves the data aware control. I tried to use OnGetText but it seems that MaskUtils FormatMaskText has some difficulties with masks that end with ";0;_". Lazarus 1.2.4 Windows 7 ---------------------------------------------------------------------- Walmir · 2014-08-07 12:21 No one can help me with this? ---------------------------------------------------------------------- BigChimp · 2014-08-07 12:23 You can post a full compilable project that demonstrates the problem as an attachment (zip file). Others may then be more motivated to help you and even if you don't get help, you can use it when reporting a bug in the bugtracker. ---------------------------------------------------------------------- rvk · 2014-08-09 00:10 An EditMask of a TField is used only when editing that field. For a TNumericField you could use the DisplayFormat property. For other field-types you need to write an OnSetText and OnGetText for the field. You can read about how to do this here: http://stackoverflow.com/questions/5617205/can-i-use-an-edit-mask-to- format-output-not-just-validate-input Quote from: Walmir on August 01, 2014, 09:36:09 pmI tried to use OnGetText but it seems that MaskUtils FormatMaskText has some difficulties with masks that end with ";0;_". You need to show us that code so we could see why it's not working. ---------------------------------------------------------------------- Walmir · 2014-08-09 15:37 Quote from: rvk on August 09, 2014, 02:10:12 amAn EditMask of a TField is used only when editing that field. I was not aware of this. In Delphi I used TField EditMask both to display and edit. Quote from: rvk on August 09, 2014, 02:10:12 amFor a TNumericField you could use the DisplayFormat property. For other field-types you need to write an OnSetText and OnGetText for the field. You can read about how to do this here: http://stackoverflow.com/questions/5617205/can-i-use-an-edit-mask-to- format-output-not-just-validate-input As I said, I tried to use OnGetText but it seems that MaskUtils FormatMaskText has some difficulties with masks that end with ";0;_". No serious developer will store the mask in the database, as in "(99)9999-999;1;_". In this way, the masks works fine (sure!). Quote from: rvk on August 09, 2014, 02:10:12 amYou need to show us that code so we could see why it's not working. Please see my previous post. ---------------------------------------------------------------------- rvk · 2014-08-09 16:08 Quote from: Walmir on August 09, 2014, 05:37:34 pmQuote from: rvk on August 09, 2014, 02:10:12 amYou need to show us that code so we could see why it's not working. Please see my previous post. I can't find anywhere in your code where you tried the onGetText as suggested. Can you point it out? For example... the following works fine for me: Code: [Select]procedure TdmData.qryFornCNPJGetText(Sender: TField; var aText: string;   DisplayText: boolean); begin   aText := TStringField(Sender).Value;   if DisplayText then // when displaying the text do this     aText := FormatMaskText('00\.000\.000\/0000\-00;0;_', aText); end; Edit: You can do it even more universal like this: Code: [Select]procedure TdmData.qryFornCNPJGetText(Sender: TField; var aText: string;   DisplayText: boolean); begin   aText := Sender.AsString;    if DisplayText and (aText <> '') and (Sender.EditMask <> '') then      aText := FormatMaskText(Sender.EditMask, aText); end; So there is no need to copy the EditMask to your code. ---------------------------------------------------------------------- Walmir · 2014-08-11 17:07 Sorry, I removed OnGetText from my code because I thoght there was a bug. But the real problem was that I was trying to use OnGetText both to display the mask and edit it, not even testing DisplayText. ---------------------------------------------------------------------- Walmir · 2014-08-11 17:16 Ok, So I will use OnGetText to display fields that have the property EditMassk set. Will I also need an OnSetText event on these fields? ---------------------------------------------------------------------- rvk · 2014-08-11 18:21 Quote from: Walmir on August 11, 2014, 07:16:01 pmWill I also need an OnSetText event on these fields? You could test this yourself...  But no, you don't need the OnSetText. The field-value itself stays "clean" without the separators. Only when testing for DisplayText in OnGetText the separators are added but that value is not used besides for display purposes (if DisplayText is true). Because the field is "clean" you don't need the OnSetText.