?
Solved

cursor position

Posted on 2003-12-08
17
Medium Priority
?
464 Views
Last Modified: 2010-04-03
i have a mask edit with the following input; 999/999/999/999 ; what i want to be able to do is that when the user presses the right or left arrow key i would like the cursor pointer to move to the next part of the maskedit, like this

user enters 1  /   /   /
then after he presses the right arrow key , supposing H is the cursor

1H /   /   /

 instead  i want the cursor to go

1   / H   /   /
then if they press left again
1   /    /H   /    and if they do it backwards i would like to the cursor to come to the previous part so
1   /   /   /H  user presses left arrow 1  /  /H   / and so on
how would this be possible? I was thinking maybe the right and left arrow keys have a control character and when they are pressed i could tell the cursor to move differently;  Hope the question was clear enough.

thanks in advance
0
Comment
Question by:itektas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 7
17 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9895992
maybe something like this

procedure TForm1.MaskEdit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = vk_right then
    case MaskEdit1.SelStart of
      0..2 : MaskEdit1.SelStart := 4;
      4..6 : MaskEdit1.SelStart := 8;
      8..14: MaskEdit1.SelStart := 12;
    end;

  if key = vk_left then
    case MaskEdit1.SelStart of
      12..14 : MaskEdit1.SelStart := 8;
      8..10 : MaskEdit1.SelStart := 4;
      0..6: MaskEdit1.SelStart := 0;
    end;
  MaskEdit1.selLength := 1;
  key := 0;

end;

not tested on all cases


meikl ;-)
0
 

Author Comment

by:itektas
ID: 9896084
i get undeclared identifier vk_right & vk_left?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9896156
>i get undeclared identifier vk_right & vk_left?
ensure that windows-unit is included in the uses clause
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:itektas
ID: 9896240
tried to put "windows-unit" and "windows" in the uses part, but i get
[Fatal Error] Unit1.pas(7): File not found: 'Windows.dcu'
what could be wrong?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9896259
what delphi version do u use?
0
 

Author Comment

by:itektas
ID: 9896312
delphi 7 ; but kylix ( linux)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9896425
pu, kylix, must recherche
0
 

Author Comment

by:itektas
ID: 9896439
pardon? i didnt understand  =)
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 200 total points
ID: 9896462
well, ok,

the keycodes are declared in the unit qt (should be added into the uses-clause),

the constants are

Key_Left
Key_Right

so you have to replace in my sample above

procedure TForm1.MaskEdit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = key_right then
    case MaskEdit1.SelStart of
      0..2 : MaskEdit1.SelStart := 4;
      4..6 : MaskEdit1.SelStart := 8;
      8..15: MaskEdit1.SelStart := 12;  //i replaced here also 14 with 15
    end;

  if key = key_left then
    case MaskEdit1.SelStart of
      12..15 : MaskEdit1.SelStart := 8; //i replaced here also 14 with 15
      8..10 : MaskEdit1.SelStart := 4;
      0..6: MaskEdit1.SelStart := 0;
    end;
  MaskEdit1.selLength := 1;
  key := 0;

end;

hope it works now under linux

meikl ;-)
0
 

Author Comment

by:itektas
ID: 9896489
works perfect!  thanks mate!  Just one last question tho, the only part in this code i dont quiet understand is the last bit,  MaskEdit1.selLength := 1;
  key := 0;

what is that for?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9896532
>MaskEdit1.selLength := 1;
marks the digit you jump to as selected
>key := 0;
ensures that the key is not processed further

but maybe you can left it out
for kylix/linux

(have no linux -> can't test it there)

glad you like it

meikl ;-)
0
 

Author Comment

by:itektas
ID: 9896551
ok cool, it works better when i leave it =)
0
 

Author Comment

by:itektas
ID: 9898413
just a detail that i have just noticed now actually, normally in an editmask when the user enters letters nothing happens, but now when the user enters letters it appears as a space, could i add a line to change that? so that it ignores it like it does it in a normal editmask?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9898437
well, not looked in yet,
but you could use the onKeypressEvenet like

if key = #32 then key := #0;

looking tomorrow, if this happens also by me (at windows)

meikl ;-)
0
 

Author Comment

by:itektas
ID: 9898568
yeah i have tried something similar to that actually using the onkeypress what i had done was

procedure Tform1.MaskEdit1Keypress( Sender: TObject; var Key: char);

begin

if not (Key in ['0','1','2','3','4','5','6','7','8','9'', #8]) then

begin

Key := #0;

end;
end;

the one you said is pretty similar but didnt work either, its weird because normally editmasks never let the letters do anything, and adding this code didnt seem to solve it :/
0
 

Author Comment

by:itektas
ID: 9900938
leaving out  the    key := 0;  line from the original code seems to do the job!
0
 

Author Comment

by:itektas
ID: 9901016
actually no! that doesnt seem to solve it, i hate it when i think i solved a problem then i come across a new one! :( When i remove that line the cursor positions get mixed up, so they start in the middle of the next part instead of the beginning. I'll look again tommorow
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month11 days, 12 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question