Delphi Caret Position Tedit

Position

  1. Delphi Tedit Get Caret Position
  2. Delphi Tedit Caret Position
  3. Delphi Cursor Position In Tedit

Once in a while you want to set the caret position (aka cursor position) in a TMemo to a given line and character in that line. If you google for it you will find lots of hits that tell you to do the following:

Problem/Question/Abstract: How to determine the caret position in a TMemo. Answer: You can use the Windows API messages EMLINEFROMCHAR and EMLINEINDEX to determine the current line and offset within that line (starting from SelStart). LineNum: longint. Delphi – Indy idTCPServer and idTCPClient. This is a simple example for usign Nevrona Indy components in Delphi to create a small server application using TCP/IP protocol. TO simplify we can build an example where there is a Server Application that recive a string from a Client App. And then return that string to the Client, but we use. Any one have any idea on how to select an area of text in a TEdit and have the cursor at the beginning of the selection. Eg: TEdit.Text:= 'Delphi Rules'; TEdit.SelStart:= 7; TEdit.SelLength:= 5; TEdit should now display 'Delphi Rules' with the last word selected (or something close to that) and the cursor at the end of the text.

or without the ugly with statement

But that looks to be at least pre-Delphi 2007 because there already is a TMemo.CaretPos property that does the same:

This is a lot easier to understand than the above. Note that you can’t just assign only x or y like this:

This won’t work, because accessing CaretPos calls a getter method that returns a TPoint value. Changing this value does not change the CaretPos property, you must write the actual CaretPos property.

Unfortunately, while this works fine in general, Borland has introduced a bug in TCustomGrid.Paint that breaks this (both) code. If you have got a TCustomGrid descendant (TStringGrid and friends) on the form or a different form, you might find that the caret of the memo shows at the position where it would be on the grid. See QC 25702 for a description and workaround.
Warning:
The workaround requires you to modify the VCL unit Grids.pas. To do that you should copy it from the Delphi installation to your project’s source code, add it to your project and only then modify it. Otherwise you might end up with a Delphi update overwriting it or even worse, failing to install.

Caret Position

How do I get the coordinates of the caret position (system wide) ?

thanks for help

tom

Re:Caret Position


Quote
> How do I get the coordinates of the caret position (system wide) ?
What do you mean with 'system wide'?

Re:Caret Position


The GetCursorPos function retrieves the cursor's position (mouse position),
in screen coordinates.
What I want is a function GetCaretPos that retrieves the caret's position in
screen coordinates.(in any application)

Ok ?

thanks for help

tom

news:39576F97.7EBFD471@spam.fly.to...
Quote
> > How do I get the coordinates of the caret position (system wide) ?

> What do you mean with 'system wide'?

Re:Caret Position


Quote
Thomas wrote:
> Still, my problem is to get the Caret Position (System wide !!)
> The GetCaretPos(..) only works in my application but not in others.

> thanks for further help

Try getting the handle of the other window and then passing it to
GetCaretPos(..)

Re:Caret Position


Quote
> The GetCursorPos function retrieves the cursor's position (mouse position),
> in screen coordinates.
> What I want is a function GetCaretPos that retrieves the caret's position in
> screen coordinates.(in any application)
Because only one window at a time can have the keyboard focus or be active,
there is only one caret in the system. Generally, each window that accepts
keyboard input must create the caret when it receives the keyboard focus and
destroy the caret when it loses the keyboard focus.

The caret is a shared resource; there is only one caret in the system. A window
can set the caret position only if it owns the caret.

You cannot assume the currently active window has a caret. You must find the
window that currently has the caret (active window) and then use ClientToScreen
function to replace the client coordinates in the POINT structure with the
screen coordinates.

Re:Caret Position


How can I pass it to GetCaretPos ??
That function doesn't use a handle !
Quote
Topprolmc <Toppro...@Starpower.net> wrote in message
news:39579F68.CD7051AE@Starpower.net...
Quote

> Thomas wrote:

> > Still, my problem is to get the Caret Position (System wide !!)
> > The GetCaretPos(..) only works in my application but not in others.

> > thanks for further help

> Try getting the handle of the other window and then passing it to
> GetCaretPos(..)

Delphi

Re:Caret Position


Still, my problem is to get the Caret Position (System wide !!)
The GetCaretPos(..) only works in my application but not in others.

thanks for further help

tom

news:39577DD3.C5FF4FEB@spam.fly.to...
Quote
> > The GetCursorPos function retrieves the cursor's position (mouse
position),
> > in screen coordinates.
> > What I want is a function GetCaretPos that retrieves the caret's
position in
> > screen coordinates.(in any application)

> Because only one window at a time can have the keyboard focus or be
active,
> there is only one caret in the system. Generally, each window that accepts
> keyboard input must create the caret when it receives the keyboard focus
and
> destroy the caret when it loses the keyboard focus.

> The caret is a shared resource; there is only one caret in the system. A
window
> can set the caret position only if it owns the caret.

> You cannot assume the currently active window has a caret. You must find
the
> window that currently has the caret (active window) and then use
ClientToScreen
> function to replace the client coordinates in the POINT structure with the
> screen coordinates.

Delphi Tedit Get Caret Position

Re:Caret Position


Quote
In article <8j7uqj$...@bornews.borland.com>, Thomas wrote:
> Still, my problem is to get the Caret Position (System wide !!)
There is no way to do that i know of.

Peter Below (TeamB) 100113.1...@compuserve.com)
No replies in private e-mail, please, unless explicitly requested!

Re:Caret Position


Thomas,
May be, what you want to know is the Mouse Coordinates system wide, which
is very diferent than the Caret Position. The caret, as you may know, is the
Blinking
cursor used in TEdit and TMemo among others controls.

rgs, jos

Thomas <thomas...@gmx.ch> escribi en el mensaje de noticias
8j7lk0$q...@bornews.borland.com...

Quote
> How do I get the coordinates of the caret position (system wide) ?

> thanks for help

> tom

Re:Caret Position


Anyone can tell me where i can find some docs about winapi

Re:Caret Position


Quote
'Jos Nazario' <jnaza...@infordesporto.pt> wrote in message
news:3959fb2e@dnews...
Quote
> Anyone can tell me where i can find some docs about winapi
Click Help, you will see a link for Windows SDK. Otherwise all the help
files (including API) are on the start menu. Otherwise, try:

http://msdn.microsoft.com/library/psdk/portals/win32start_1n6t.htm
Hope that helps.

Best regards
--
L.J. - UK
ICQ: 42252330
Remove the monarchy to email me
--
Please do not request support for OP (Delphi),
Java, C++ or PHP by private email or ICQ.

Re:Caret Position

Re:Caret Position


Quote
'Marius Bunescu' <a...@crinsoft.ro> wrote in message
news:395A04BD.A2761CD5@crinsoft.ro...
Hence the MSDN link I quoted! ;)

Cheers
--
L.J. - UK
ICQ: 42252330
Remove the monarchy to email me
--
Please do not request support for OP (Delphi),
Java, C++ or PHP by private email or ICQ.

Re:Caret Position

Go to page: [1][2]

1. Caret position to correct pixel position

Delphi

2. Get Caret Position from Mouse Location?

3. Inserting text a caret position in a memo

Delphi Tedit Caret Position

4. Caret Position in TRichEdit

5. Caret position in TMemo

6. Richedit caret position on backward selection

Delphi Cursor Position In Tedit

7. Caret Position in a Memo or Rich Edit

8. richedit problem (adding text on current caret position)

9. RichEdit (D3) - setting/getting desired caret position

10. TMemo caret position