Recent

Author Topic: [SOLVED] Is this a bug in TMaskEdit?  (Read 8596 times)

EganSolo

  • Full Member
  • ***
  • Posts: 211
[SOLVED] Is this a bug in TMaskEdit?
« on: March 03, 2021, 08:07:43 am »
To see what I'm talking about, you simply have to
  • Create a new GUI app
  • Drop a TMaskEdit control on the form
  • Implement the Form OnCreate event and add the two lines as seen below:

Code: Pascal  [Select][+][-]
  1. Procedure TForm1.FormCreate(Sender: TObject);
  2. Begin
  3.   With MaskEdit1 do
  4.   begin
  5.     EditMask := '!\(000\)-000-0000;0;_';
  6.     Caption  := '6142345678';
  7.     //Comment the line above and uncomment the line below if you want to test it with Text instead of Caption: same thing.
  8.    //Text := '6142345678';
  9.   End;
  10. end;    
  11.  

Run the program, and you'll see the output as seen in the attached image: The component is properly displaying the phone number as (614)-234-5678 but it's highlighting '(614)-234-' instead of highlighting the entire string. The length of '(614)-234-' is ten which is the length of the phone number, so it seems that it's behaving as if it's editing a non-masked string.

Curiously, SelectAll is not overridden in TCustomMaskEdit and its implementation in TCustomEdit reads as follows:

Code: Pascal  [Select][+][-]
  1. procedure TCustomEdit.SelectAll;
  2. begin
  3.   if Text <> '' then
  4.   begin
  5.     SetSelStart(0);
  6.     SetSelLength(UTF8Length(Text));
  7.   end;
  8. end;
  9.  

That code is selecting Text. If I'm reading the documentation of TMaskEdit at https://lazarus-ccr.sourceforge.io/docs/lcl/maskedit/tmaskedit.html, Text is
The Text string that is to be masked (or not). If that's the case, then shouldn't we override SelectAll in TCustomMaskEdit and have it select the masked text?
 
« Last Edit: March 03, 2021, 07:18:38 pm by EganSolo »

Bart

  • Hero Member
  • *****
  • Posts: 4225
    • Bart en Mariska's Webstek
Re: Is this a bug in TMaskEdit?
« Reply #1 on: March 03, 2021, 06:26:25 pm »
SelectAll should select all visible text.
It obviously doesn't, which is a bug.
I'll try and fix it.

Bart
« Last Edit: March 03, 2021, 06:45:14 pm by Bart »

Bart

  • Hero Member
  • *****
  • Posts: 4225
    • Bart en Mariska's Webstek
Re: Is this a bug in TMaskEdit?
« Reply #2 on: March 03, 2021, 06:53:01 pm »
Fixed in r64741.
Please test (with trunk) and report back.

Bart

EganSolo

  • Full Member
  • ***
  • Posts: 211
Re: [SOLVED] Is this a bug in TMaskEdit?
« Reply #3 on: March 03, 2021, 07:19:00 pm »
Thanks, Bart. It works!  :D

Bart

  • Hero Member
  • *****
  • Posts: 4225
    • Bart en Mariska's Webstek
Re: [SOLVED] Is this a bug in TMaskEdit?
« Reply #4 on: March 03, 2021, 08:45:30 pm »
This bug has been there for ages.
Nobody spotted it before.

Bart

EganSolo

  • Full Member
  • ***
  • Posts: 211
Re: [SOLVED] Is this a bug in TMaskEdit?
« Reply #5 on: March 03, 2021, 11:30:16 pm »
I've noticed another minor bug, an annoyance really,  that may be fixed with a slight mod to what you just did:

Using the mask: !\(000\)-000-0000;0;_
Set Text to any phone number (123-456-7890)

As soon as the edit mask has the focus, it will now (correctly) highlight the entire number with all the characters in it.

Hit backspace: the cursor will settle on the left paren so that if you type a digit, the edit mask will gobble it and it won't show up. You have to first hit the right arrow to move the cursor to the first digit position and then enter a digit.

The fix would be to move the cursor to the first pos that accepts input

Let me know if you'd like me to send you a ready-made code that demonstrates that behavior.

jamie

  • Hero Member
  • *****
  • Posts: 4366
Re: [SOLVED] Is this a bug in TMaskEdit?
« Reply #6 on: March 04, 2021, 02:08:44 am »
Bugs Bugs Bugs..

  :o

Not only does it do that, it also does not behave correctly If you decide to cut short out of the editing and don't complete the input.

using 000 is will fault, and there is no way that I can see to catch it? It pops up a fault screen either way in or out of debug mode and where would you put a Try and catch on this ? 8)

using 9999 for the mask is suppose to allow you to not be forced to enter all of the numbers and it should not fault, but it does so there you go..

Also, you shouldn't need the "\" to force the "(" etc


Good luck with the bug repairs  :)


P.S.
  Playing with the trunk brings surprises , it seems when you are changing values in the OI they don't seem to update the resources or design time values always if you leave the IO tablet and hit compile, your change didn't get put in..
 
 It seems you have to HIT ENTER on the line or click to another input in the OI tablet, leaving the tablet before hitting enter on a change does not make a change.
« Last Edit: March 04, 2021, 02:34:24 am by jamie »
The only true wisdom is knowing you know nothing

Bart

  • Hero Member
  • *****
  • Posts: 4225
    • Bart en Mariska's Webstek
Re: [SOLVED] Is this a bug in TMaskEdit?
« Reply #7 on: March 04, 2021, 08:16:15 pm »
Hit backspace: the cursor will settle on the left paren so that if you type a digit, the edit mask will gobble it and it won't show up. You have to first hit the right arrow to move the cursor to the first digit position and then enter a digit.
It is supposed to move to the first editable position, so this is a bug.

Bart

Bart

  • Hero Member
  • *****
  • Posts: 4225
    • Bart en Mariska's Webstek
Re: [SOLVED] Is this a bug in TMaskEdit?
« Reply #8 on: March 04, 2021, 08:19:29 pm »
using 000 is will fault, and there is no way that I can see to catch it? It pops up a fault screen either way in or out of debug mode and where would you put a Try and catch on this ? 8)

Well, this all is modellead after the Delphi behaviour (in some aspects it's even worse, trust me).
Please complain to them (not to me).

You can handle the exceptions in a Application.OnException handler.

Bart

Bart

  • Hero Member
  • *****
  • Posts: 4225
    • Bart en Mariska's Webstek
Re: [SOLVED] Is this a bug in TMaskEdit?
« Reply #9 on: March 04, 2021, 08:51:47 pm »
Hit backspace: the cursor will settle on the left paren so that if you type a digit, the edit mask will gobble it and it won't show up. You have to first hit the right arrow to move the cursor to the first digit position and then enter a digit.
It is supposed to move to the first editable position, so this is a bug.

Fixed in r64744.
Please test.

Bart

winni

  • Hero Member
  • *****
  • Posts: 2292
Re: [SOLVED] Is this a bug in TMaskEdit?
« Reply #10 on: March 04, 2021, 08:57:28 pm »
Hi!

TMaskedit is scrap since Delphi 1.
And with every Delphi version they fixed some bugs.
And created  some new bugs.

We are talking about a timespan of 25 years!

If someone is courageous:
Make a new design and a new TMaskedit.
Without bugs. So not Delphi compatible.
That would help a lot of people.
 
Winni

Bart

  • Hero Member
  • *****
  • Posts: 4225
    • Bart en Mariska's Webstek
Re: [SOLVED] Is this a bug in TMaskEdit?
« Reply #11 on: March 04, 2021, 09:05:31 pm »
Feel free to implement it.

The basic design flaw IMO is that it raises exceptions, which you can only catch if you implement an Application.OnException handler.
A simple OnValidateError event would have given the programmer a better change of fighting the beast.

And why EDBEditError and not simply EMaskEditError?

Somebody suggested once tha have a similar control where "EditMask" could be a RegEx.

Bart

winni

  • Hero Member
  • *****
  • Posts: 2292
Re: [SOLVED] Is this a bug in TMaskEdit?
« Reply #12 on: March 04, 2021, 09:26:38 pm »
Feel free to implement it.

Bart

Don't try to teach an old horse new tricks ...

My workaround is since 25 years the same:

Take a simple TEdit.
On every onChange start a little parser for your current needs and see if the change is allowed.
If not take the string before.
Not realy a big trick but before I get a gastric ulcer because of TMaskEdit ...

Winni

Bart

  • Hero Member
  • *****
  • Posts: 4225
    • Bart en Mariska's Webstek
Re: [SOLVED] Is this a bug in TMaskEdit?
« Reply #13 on: March 04, 2021, 09:38:42 pm »
In the old days I had an application made in D1, later D3 that relied heavily on TMaskEdit to enforce correct user input (floats).
It was in fact fool proof.

Then I made the switch to Lazarus and started to re-implement my Delphi apps in Lazarus (no proper conversion tool then).
TMaskEdit was non-functional to say it politely.
A simple Text := 'Something' could raise an exception.

So I sat out and started to almost re-implement it.
Just by black-boxing the behaviour against D3.

I made some subtle deviations from Delphi (e.g. OnExit fires before validation, so you can validate yourself).
Later on I added some nice features which Delphi does not have, like a mask for hexadecimal input, the possibility to temporarily disable the mask (and later re-enable it).

After I had done all that, I started out re-implementing my Delphi app, only to find out we (Lazarus) have a TFloatSpinEdit, which Delphi (3) does not.
So, I abandoned TMaskEdit and have not found a use for it since.

Bart

jamie

  • Hero Member
  • *****
  • Posts: 4366
Re: [SOLVED] Is this a bug in TMaskEdit?
« Reply #14 on: March 04, 2021, 10:58:39 pm »
I found out the 99999 in place of the 0000 does indeed prevent the exception which means 9 instead of 0 for digits to indicate an incomplete edit is ok..

 But still, using the exception method, maybe there should be a OnError event with flags indication the error for the maskedit and if the event is not assigned then simply process it as it is now..


  Just an idea really..
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018