Solved

Controlling the keyboard cursor in TEdit

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Simple Delphi Question 9 90
TServerSocket - file via sendbuf or Text via sendtext ? 1 54
SUM 2 INTEGER ARRAYS INTO 1 10 100
Dev express lookupcombo 3 28
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…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

778 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