[fpc-pascal] TMaskUtils.ValidateInput function: how is it supposed to behave?

Bart bartjunk64 at gmail.com
Sun Apr 17 17:45:12 CEST 2016


I cannot find any documentation about TMaskUtils.ValidateInput
function (unit MaskUtils).
AFAICS Delphi does not have such a class?
(ref: http://docwiki.embarcadero.com/Libraries/XE6/en/System.MaskUtils)

There are some bugreports about this unit in Mantis which got me interested.

See the attached demo program.

It outputs:
Mask : "###"
Value: "ABCD"
VI   : "   "   (Shouldn't this fail?)

Mask : "999"
Value: "ABCD"
VI   : "   "   (Shouldn't this fail?)

Mask : "000"
Value: "ABCD"
ValidateInput Failed

Mask : "LLL"
Value: "1234"
ValidateInput Failed

Mask : "lll"
Value: "1234"
VI   : "   "   (Shouldn't this fail?)

Mask : "AAA"
Value: "[{|/"
ValidateInput Failed

Mask : "aaa"
Value: "[{|/"
VI   : "   "   (Shouldn't this fail?)

I am the maintainer of the Lazarus MaskEdit unit.
I find the results rather confusing and inconsistent with
Lazarus/Delphi MaskEdit behaviour.

When the mask contains mask-characters that mean "value must be of
type XYZ, but not required" the ValidateInput accepts any input.
The same characters in MaskEdit (both Lazarus and Delphi) interpret
this as: "if you put anything in that place it must be of type XYZ,
but you may leave this place empty (e.g. a blank)".
Basically ValidateInput now treats '#', '9', 'l' and 'a' as if it were
'c' (any character allowed here). This seems wrong to me.

However, since the function lacks any documentation one can argue that
current behaviour is correct.

To me the (IMO more logical) behaviour of the ValidateInput function
could be described as the result of these actions in a LCL/VCL

- have a MaskEdit1: TMaskEdit
- do MaskEdit1.EditMask := Mask
- do MaskEdit1.Text := Value
- do MaskEdit1.ValidateEdit
- if no exception is raised then the result will be
MaskEdit1.EditText, but with all "SpaceChar" repkaced by #32.

I.o.w. the function shall raise an exception it Value (after appllying
Mask to it) does NOT match the Mask.

So, is it a bug?
If so, I'll open a ticket in Mantis for it (and the discussion should
then move there).

-------------- next part --------------
A non-text attachment was scrubbed...
Name: mutest.lpr
Type: application/octet-stream
Size: 2484 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20160417/42c64482/attachment.obj>

More information about the fpc-pascal mailing list