Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Controlling the keyboard cursor in TEdit

Posted on 1997-08-28
4
Medium Priority
?
473 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
[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
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 300 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

718 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