Solved

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

Posted on 2003-11-05
14
263 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
  • 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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now