Board index » delphi » Tedit & Tedit Mask On key question

Tedit & Tedit Mask On key question

I need to know where is the Tedit cursor during onKeypressevent.

This is necessary because my Mask will be a mutant mask, and also I need to
fire some events while user is typing.

For example

The actual State of Tedit is empty.= ''

The user type the first letter,'A' the var key tell-me that the letter 'A'is
typed but not that the 'A' is on first position of the string, and I need
that.

Another example

The actual State of Tedit is filled with 'ABC12345'.

The user type the back space 3 times and the cursor actually are between 2
and 3 then he type 'Y'' the var key tell-me that the letter 'Y'is typed but
not that the 'Y' is on 6th position of the string, and I need that.

The State of Tedit After typing will be 'ABC12Y345'.

How can I know where are the cursor , on the onkeypressevent ?

Regards

SAci

 

Re:Tedit & Tedit Mask On key question


Look at the SelStart property. Provided the user has no selection, it shows
the position of the cursor.

Ray

Quote
"Saci" <nos...@bol.com.br> wrote in message news:3c6dec6f_2@dnews...
> I need to know where is the Tedit cursor during onKeypressevent.

> This is necessary because my Mask will be a mutant mask, and also I need
to
> fire some events while user is typing.

> For example

> The actual State of Tedit is empty.= ''

> The user type the first letter,'A' the var key tell-me that the letter
'A'is
> typed but not that the 'A' is on first position of the string, and I need
> that.

> Another example

> The actual State of Tedit is filled with 'ABC12345'.

> The user type the back space 3 times and the cursor actually are between 2
> and 3 then he type 'Y'' the var key tell-me that the letter 'Y'is typed
but
> not that the 'Y' is on 6th position of the string, and I need that.

> The State of Tedit After typing will be 'ABC12Y345'.

> How can I know where are the cursor , on the onkeypressevent ?

> Regards

> SAci

Re:Tedit & Tedit Mask On key question


Quote
In article <3c6dec6f_2@dnews>, Saci wrote:
> I need to know where is the Tedit cursor during onKeypressevent.

Look at the edits SelStart property.

--
Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be

Re:Tedit & Tedit Mask On key question


You are nearly their
SelStart property points to the curser or the start of the selected text
SelStart has read and write capabilities
If it is moved by your keyboard left or right do not adjust it
At times I get confused especially switching between left and right text
alignment
I hate the naming that is chosen of "SelStart" It should be "CurserStart"

Quote
Ray Cernis <cern...@attglobal.net> wrote in message

news:3c6e3a71_4@news2.prserv.net...
Quote
> Look at the SelStart property. Provided the user has no selection, it
shows
> the position of the cursor.

> Ray

> "Saci" <nos...@bol.com.br> wrote in message news:3c6dec6f_2@dnews...
> > I need to know where is the Tedit cursor during onKeypressevent.

> > This is necessary because my Mask will be a mutant mask, and also I need
> to
> > fire some events while user is typing.

> > For example

> > The actual State of Tedit is empty.= ''

> > The user type the first letter,'A' the var key tell-me that the letter
> 'A'is
> > typed but not that the 'A' is on first position of the string, and I
need
> > that.

> > Another example

> > The actual State of Tedit is filled with 'ABC12345'.

> > The user type the back space 3 times and the cursor actually are between
2
> > and 3 then he type 'Y'' the var key tell-me that the letter 'Y'is typed
> but
> > not that the 'Y' is on 6th position of the string, and I need that.

> > The State of Tedit After typing will be 'ABC12Y345'.

> > How can I know where are the cursor , on the onkeypressevent ?

> > Regards

> > SAci

Re:Tedit & Tedit Mask On key question


Thank you, SelStart is solve my problem

Another extra question why OnKeyDown, OnKeyPress and OnKeyUp exist ? This
question is more philosophic than a practice one.

O Guess that only OnKeyDown and OnKeyUp are capable of everything when
talking about keyboard.

In another work why we need 3 kinds of On key events?.

Saci

Re:Tedit & Tedit Mask On key question


Quote
In article <3c706321_2@dnews>, Saci wrote:
> Another extra question why OnKeyDown, OnKeyPress and OnKeyUp exist ? This
> question is more philosophic than a practice one.

The roots of these methods are in the way the Windows API handles keyboard
input. When you press a key (any key) the keyboard driver calls
keybd_event, which in turn puts a WM_KEYDOWN message into the message queue
of the application with focus. The apps message loop fetches the message
from the queue and does some processing on it before handing it to the
control with focus as a CM_KEYDOWN message. This control will then fire the
OnKeyDown event. If the event did not "swallow" the key press by setting
key to 0 the message loops code will then call the API function
TranslateMessage. This function examines the key code and the state of all
the modifier keys (Shift, Ctrl, Alt) to see if the key should result in a
character. If it does the function places a WM_CHAR message into the
applications message queue and returns. For keys that do not result in
characters it does  nothing but return. The next action of the message loop
code is to call DispatchMessage, another API function. This finally
delivers the WM_KEYDOWN message to the target control.

The next message the loop fetches form the queue will now be the WM_CHAR
message generated by TranslateMessage( if it did create one), which also
gets processed and served up to the control with focus as a CM_CHAR
message. This fires the OnKeyPress event. As you see this event is only
fired if the key creates a character. So if you need to process characters
you do it in the OnKeyPress event, if you need to process function keys,
cursor keys etc. you do it in the OnKeyDown event. As you probably know you
can again swallow the key in OnKeyPress by setting it to #0. If you do not
do that the message loop will send the key on as WM_CHAR to the control,
which then may do a default action on it (like inserting it into the
control). Not that some keys like Tab, Enter, Backspace do in fact create
characters in the range #1..#31 (#9, #13,#8 for the three keys mentioned).

If you want to process characters in OnKeyDown you have to do all the work
TranslateMessage does yourself, and it's by no means easy do to. Just think
about things like accented characters (dead key combinations) and
Alt-numpad sequences.

When you let go of the key it creates a WM_KEYUP message, which gets
processed much like WM_KEYDOWN and will fire the OnKeyUp event. This is in
fact an event you will rarely use, unless you have a situation where no
action should be done until the user lets go if the key.

--
Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be

Re:Tedit & Tedit Mask On key question


Thank you again.

This Group is the main reason to love Delphi..............

Other Threads