Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2003-11-05
14
Medium Priority
?
272 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

604 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