?
Solved

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

Posted on 2003-11-05
14
Medium Priority
?
271 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 400 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
Industry Leaders: 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month12 days, 2 hours left to enroll

752 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