Solved

Controlling the keyboard cursor in TEdit

Posted on 1997-08-28
4
472 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 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

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.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month8 days, 16 hours left to enroll

617 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