[Lazarus] floating point mask

Hans-Peter Diettrich DrDiettrich1 at aol.com
Mon Dec 7 17:45:41 CET 2009


ik schrieb:

> I'm trying to create some sort of calculator for specific task.
> I require to allow to input only floating point or integer numbers.
> I thought to use TMaskEdit for it, but how can i tell it a rule to allow 
> me arbitrary number length including a floating point on arbitrary 
> position ?

TMaskEdit IMO has very limited use, restricted to the insertion or 
removal of fixed "decoration" for some input.

> In regex such rule will look like:
> 
> ^(\d+|\d+\.\d+)$
> 
> Does the TMaskEdit capable of defining such pattern (not in the syntax 
> of regex) ? If not, is there any tool that can provide me this type of 
> patterns ?

You can use any input component, and check e.g. in OnKeyPress whether 
the resulting string would be valid. If not, reject the input character.

You can use any regex library for the check, but IMO that's overkill 
with a single constant format. In your case I'd use the conversion 
function itself, e.g. Val(), to determine whether the input is valid.

DoDi





More information about the Lazarus mailing list