Solved

TRichEdit, D5, How To Locate Exact Carot Pos on Screen.

Posted on 2003-11-05
14
268 Views
Last Modified: 2010-04-05
All i want to do is locate the carot pos ( for displaying a hint by the text cursor ( a bit like delphi hints ) ), but no matter what i do, im having a problem getting the pos if the RichEdit has lots of text, and the page is scrolled down, the carot pos allways seems to be the position from the top of the richedit.
i cannot find any reference to the actual pos, or even the page showing rect / point variabls, so there doesnt even seem to be a way of deriving the value.

so can anyone tell be how to get the exact carot pos in a TRichEdit, taking into consideration scrolling / Screen position.
but either :
get pos,
Get showing screen pos of the richedit so i can work it out,
get pos from screen directly,
or some other means with code example.

Thank you in advance.
Kristian
0
Comment
Question by:Kristian
[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
  • 8
  • 6
14 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9686057
a sample

unit Unit1;

interface


uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    RichEdit1: TRichEdit;
    Label2: TLabel;
    Timer1: TTimer;
    procedure RichEdit1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses richedit; //richedit used


//mousecursor
procedure TForm1.RichEdit1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  label1.Caption := inttostr(x)+':'+inttostr(y);
end;

//caret coords within the richedit-clientarea
procedure TForm1.Timer1Timer(Sender: TObject);
var p : tpoint;
begin
  richedit1.Perform(EM_POSFROMCHAR,integer(@p),richedit1.selstart);
  label2.Caption := inttostr(p.x)+':'+inttostr(p.y); //maybe some minimal offset is needed
end;

end.

meikl ;-)
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 100 total points
ID: 9686095
if you need it converted to screen-coords

//caret cooods within the richedit
procedure TForm1.Timer1Timer(Sender: TObject);
var p : tpoint;
begin
  richedit1.Perform(EM_POSFROMCHAR,integer(@p),richedit1.selstart);
  label2.Caption := inttostr(p.x)+':'+inttostr(p.y);
  //converted to screencoords
  p := Richedit1.ClientToScreen(p);
  label3.Caption := inttostr(p.x)+':'+inttostr(p.y);
end;

meikl ;-)
0
 
LVL 1

Author Comment

by:Kristian
ID: 9686130
yeah, thats perfect.
like you said a little offset but.

i used,

function GetCarotPos(Memo : TRichedit):TPoint;
begin
  Memo.Perform(EM_POSFROMCHAR,integer(@result),Memo.selstart);
  result.x := result.x + Memo.ClientOrigin.x;
  result.y := result.y + Memo.ClientOrigin.y + Memo.DefAttributes.Height + 5;
end;

but i think ClientToScreen does the same thing doesnt it?
Anyway thank you very much.
Kristian
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:kretzschmar
ID: 9686149
>but i think ClientToScreen does the same thing doesnt it?
yep, should be the same result

glad to helped you

meikl ;-)
0
 
LVL 1

Author Comment

by:Kristian
ID: 9686172
kretzschmar,
did you just send a 3rd comment,
i got a 3rd notification, BUT i cannot view it, it only comes up with 2 comments from you, is this a EE notify bug, or EE View bug?
Kristian
0
 
LVL 1

Author Comment

by:Kristian
ID: 9686174
( after sending message, i got it now, dont worry, very wierd though ) cheers again.
K
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9686187
>is this a EE notify bug, or EE View bug?
no, its just the cache of your browser,
just use the link

Reload This Question

if this happens

meikl ;-)

0
 
LVL 1

Author Comment

by:Kristian
ID: 9686237
( same again )
so this is so i can view the message,

and i have shut explorer and pressed the link again,
have pressed refresh,
and nothing. so hopefully this message will show again.
( how can i report this to EE ? )
0
 
LVL 1

Author Comment

by:Kristian
ID: 9686266
well i did do ( re my 1st message ) what you said,
and that didnt work,
is it maybe my cache options then ?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9686272
nono,

you don't have to shutdown your browser,
nor to press the refresh button

you have on this page
(upper-left in expert mode, upper-right in normal mode)
a framed box titled "your status" followed by your name.

in this box is a link
"Reload This Question"

you have only to click on this link,
to get the actual content, thats all

meikl ;-)
0
 
LVL 1

Author Comment

by:Kristian
ID: 9686280
xx
0
 
LVL 1

Author Comment

by:Kristian
ID: 9686288
Ok found it,
i will do this in future,
Cheers.
K
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9686415
:-)) just as test

btw. this happens to me too often,
that i click the question-link
in the notification-mail and get
the old content from the browser-cache

it is really not a bug of ex-ex, its just
a normal bahaviour of the browser-technic

meikl ;-)
0
 
LVL 1

Author Comment

by:Kristian
ID: 9686419
now it worked fine that time....
K
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
oracle global variables 4 80
How to define IfThen functions in one common unit? 4 64
Unique identifier on a terminal server (rdp) 4 75
Delphi, TImage, Png 2 32
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

730 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