• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 157
  • Last Modified:

tabbing from one mask edit to another automatically

the users of my application have to enter 2 numbers in two separate mask edit fields. These are numeric values. I would like the focus to jump to the second mask edit when the first one is filled with digits (sort of like the Windows 95 authentication code.
0
sharons
Asked:
sharons
1 Solution
 
michaueCommented:
Set the MaxLength property of MaskEdit1 (at design time) to the maximum number of digits you want entered into the field.

And on the OnKeyUp event of MaskEdit1 put the following code

if Length(MaskEdit1.Text) = MaskEdit1.MaxLength then
  MaskEdit2.SetFocus;
0
 
ronit051397Commented:
michaue, Did you check it?
0
 
michaueCommented:
Yes, Why?  :)
0
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
ronit051397Commented:
michaue, Did you check it?
0
 
ronit051397Commented:
michaue, Did you check it?
0
 
ronit051397Commented:
Because if you put some mask then it's not working. Put the following mask:
MaskEdit1.EditMask:='!\(999\)000-0000);1;_'
0
 
michaueCommented:
Sorry, I didn't check it with the mask ....
0
 
michaueCommented:
Here's the sollution with mask edit characters included:

You have to declare a variable to hold the character count, and initialize it with the value of mask characters for which the user won't enter anything (like spaces etc)

You don't have to set the MaxLenght property when you add and EditMask to MaskEdit1, because it will put the value in as soos as you change the EditMask property.

Then in the KeyPress event of MaskEdit1 put the following code ...

Count := Count + 1;
if Count = MaskEdit1.MaxLenght then
  MaskEdit2.SetFocus;
0
 
ronit051397Commented:
But then if you are pressing the left arrow key, meaning going back, then the Count will not have the right value of the cursor position, so in this case it will not work properly.
0
 
michaueCommented:
Any suggestions ?
0
 
vladikaCommented:
Try it

procedure TForm1.MaskEdit1KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if MaskEdit1.SelStart = MaskEdit1.MaxLength then MaskEdit2.SetFocus;
end;

0
 
sharonsAuthor Commented:
It works great.  Thank you.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now