Solved

Controlling the keyboard cursor in TEdit

Posted on 1997-08-28
4
467 Views
Last Modified: 2009-07-29
I just tried to customize an edit control to change some
of its keys. I wish for the control to display a different
character instead of the one clicked. For example: I'll
click '1' and it'll add '2' instead. I have the translation
table I need.
What I did it to add an event handler to the KeyPress
/KeyDown events. My event handlers would temporarily
make the TEdit compo ReadOnly so that it won't respond
to the actual key pressed. The second thing I did was
to alter the edit's text property.

Eg. Edit1. Text:= Edit1. Text + 'A';

My problem: when I change the text property the text
cursor is automatically moved to the beginning of the
edit field hence not allowing me to normally use the
edit functions.

I can override the other keys ( left, right, backspace... )
to do what is needed but I wish that damn cursor to be
where it is supposed to be.

How?

Another thing, how can I change the TEdit's text alignment?

0
Comment
Question by:nir_l
4 Comments
 
LVL 1

Expert Comment

by:sassas081597
ID: 1342884
To the second question:

hRightEdit:=CreateWindow('edit',nil, ws_Child or ws_VISIBLE or WS_BORDER or WS_SCROLL or {this is the case} ES_RIGHT or es_AUTOSCROLL or ES_MULTIlINE, 100, 100, 200,100, WINDOW, HMENU(-1), hInstance, nil);

For more comment look in Help file.
0
 

Accepted Solution

by:
khenr29j earned 150 total points
ID: 1342885
The easiest way of doing what you want is to add an OnKeyPress event handler that modifies the Key parameter.
The following code will replace each character pressed by an 'a':

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  Key := 'a';
end;

0
 

Expert Comment

by:krisz
ID: 1342886
There is also a way to change the position of the caret
(the cursor), and change the selection.

It's enough in a comment.
0
 

Author Comment

by:nir_l
ID: 1342887
khenr29j...
Ok, I thank you for that. It's irritating when the most simple things sometimes get out of your eye. However, you didn't answer the alignment thing nor the cursor play thing.

sassas...
Thanks for the tip. However, I think it's better either creating a new control overriding the CreateParams method or using the WindowSetLong procedure. The first of my suggestions works fine but for some wierd reason I can't yet activate the second. Check it out if you like.

krisz...
I know the API procedures for changing the caret position but it's using pixels and not characters and messing with font widths seems to me too much.

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now