Author Topic: tRichMemo get clicked-on  (Read 431 times)


  • Newbie
  • Posts: 4
tRichMemo get clicked-on
« on: July 04, 2019, 03:00:16 pm »
How can I get the value of the URL the user clicked on with tRichMemo?  I searched the forums, and the most relevant post ended with (oh, I used htmlviewer which isn't useful for this app).

Like this : This is just one line.  And some text here is a link.

If I click on any part of the then I want to be able to figure out the entire clicked-on URL.

Using tRichMemo, I have enabled URL formatting but want to find a way to figure out WHAT URL the user CLICKED on (when they click on any).
Ideally, I wish to be able to have CONTROL+left-click open the URL.  But even just getting the clicked on URL (EM_AUTOURLDETECT'ed ) text would be just as useful.

This is what I used to enable the formatting :
CONST ENM_LINK                 = $04000000;
           EM_AUTOURLDETECT = WM_USER + 91;

procedure tfrmMain.tstBtnClick(Sender: TObject);
VAR mask : Word;

     mask := SendMessage( rtfMemo.Handle, EM_GETEVENTMASK, 0, 0);
     SendMessage( rtfMemo.Handle, EM_SETEVENTMASK, 0, mask or ENM_LINK);
     SendMessage( rtfMemo.Handle, EM_AUTOURLDETECT, Integer(True), 0);

Ideally, it'd be in onMouseDown so I can check ssCtrl in ShiftState but I would appreciate ANY way of getting the clicked-on URL.                                                                         


  • Hero Member
  • *****
  • Posts: 7338
Re: tRichMemo get clicked-on
« Reply #1 on: July 04, 2019, 03:14:30 pm »
Did you look at the sample project "links" in the "samples" folder of the RichMemo installation? Maybe that's what you are looking for.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...


  • Newbie
  • Posts: 4
Re: tRichMemo get clicked-on
« Reply #2 on: July 04, 2019, 05:00:02 pm »
Good tip. ;D  not QUITE what I was looking for, because it requires that I set the LINKs.
BUT it's an excellent start.  I didn't know the SAMPLEs were installed with the OPM, so thanks :)

I am loading RTF files and sometimes typing links.. BUT it was helpful in that I added this :

procedure tMyForm.rtfMemoLinkAction(Sender: TObject; ALinkAction: TLinkAction;
 const info: TLinkMouseInfo; LinkStart, LinkLen: Integer);

VAR wrkString : STRING;
    Counter   : LONGINT;
     Counter := LinkStart;

           DEC( Counter );
           wrkString := rtfMemo.GetText( Counter, LinkStart - Counter);
     UNTIL ( Counter = 1 ) OR
           ( Trim( UpperCase( Copy( wrkString, 1, 7 ))) = 'HTTP://' ) OR
           ( Trim( UpperCase( Copy( wrkString, 1, 8 ))) = 'HTTPS://' );

Then I can work with the wrkString...


TinyPortal © 2005-2018