Recent

Author Topic: How To: Create and React to Links in Rich Memo  (Read 303 times)

zxandris

  • Full Member
  • ***
  • Posts: 152
How To: Create and React to Links in Rich Memo
« on: March 18, 2025, 05:19:20 pm »
Hello, I want to be able to link certain text and then react to it when it's clicked, or edit it.  I currently can't figure this out.  Would anyone mind elucidating for me I'm a bit lost.  Thanks

CJ

Edit: I did mean to say this is for RichMemo, I would guess that might help :)

« Last Edit: March 19, 2025, 09:19:41 am by zxandris »

zxandris

  • Full Member
  • ***
  • Posts: 152
Re: How To: Create and React to Links in Rich Memo
« Reply #1 on: Today at 12:05:49 pm »
So I've managed to figure out how to create a link with SetLink but now I'm trying to react to a click on the link.  I've got

Code: Pascal  [Select][+][-]
  1.      
  2.      if memEdit.isLink(linkStart) then
  3.      begin
  4.          href := info.LinkRef;
  5.          ShowMessage(href);
  6.      end;
  7.  

Which is returning nothing.  I'm a little confused as to how to retrieve the hyperlink the user clicks on then react to it.  Would anyone mind helping me with that please?

CJ

paweld

  • Hero Member
  • *****
  • Posts: 1326
Re: How To: Create and React to Links in Rich Memo
« Reply #2 on: Today at 01:19:22 pm »
Code: Pascal  [Select][+][-]
  1. //set selected text as link
  2. procedure TForm1.baddlinkClick(Sender: TObject);
  3. begin
  4.   RichMemo1.SetLink(RichMemo1.SelStart, RichMemo1.SelLength, True, RichMemo1.SelText);
  5. end;  
  6.  
  7. //open link after click
  8. procedure TForm1.RichMemo1LinkAction(Sender: TObject; ALinkAction: TLinkAction; const info: TLinkMouseInfo; LinkStart, LinkLen: Integer);
  9. begin
  10.   if QuestionDlg('Open link?', 'Do you want to open the link below?' + #13#10 + info.LinkRef, mtConfirmation,
  11.     [mrYes, 'Yes', mrNo, 'No', 'IsDefault'], 0) = mrYes then
  12.     OpenURL(info.LinkRef); //open link in default browser
  13. end;  
Sample app in attachment
Best regards / Pozdrawiam
paweld

 

TinyPortal © 2005-2018