0

I'm doing a kind of grep in a Delphi app where the user can search some files in a folder for a search term. Then in a TRichEdit, for each file with a match, I'm showing a filename and below it I show lines that contain the search term.

I'd like to be able to have the filename act like a hotlink so if you click it, it will open the file in whatever the system default is. They're usually just text files, so I could also open them all in Notepad++.

I know this can be done in TRichView but I don't have access to it here. In RV, you can have any text look like a URL and when it's clicked you can do whatever you want with it. Last I checked, the regular RichEdit controls treat them only as web URLs and only let you route them to a web browser. Delphi has never done much to update lots of these standard Windows controls, and what's there isn't well documented. So I'm wondering if anybody knows this for sure.

In case it matters, I'm using Delphi 10.2.3 (Tokyo) on Windows 10.

David
  • 101
  • 1
  • 10
  • If the answer https://stackoverflow.com/questions/42532760/adding-true-hyperlink-support-to-trichedit doesn't fit your need, I have code which looks at the text where the user clicked to check for URL and return it. This code is based on the message EM_GETTEXTRANGE to extract the text around where the user clicked. If you are interested, start a new question which explicitly expose this problem (I cannot add an answer here since the question has been close). – fpiette Sep 10 '20 at 07:07
  • Remy's answer at the dupe is excellent, I am using it in my software – David Heffernan Sep 10 '20 at 07:15
  • Well, that answers my question, for sure. Thanks, Remy. @fpiette if you've got some code that already does that stuff, I'd love to see it. – David Sep 11 '20 at 02:15
  • @David "I'd love to see it" I cannot answer this question because it is closed. Ask a suitable new question. – fpiette Sep 11 '20 at 05:19
  • @fpiette Add your answer at the dupe – David Heffernan Sep 11 '20 at 06:27
  • @DavidHeffernan My answer is not a good answer for the dupe, you'll downgrade it and I don't want that! It is not about displaying an hyperlink, it is about detecting an hyperlink (or anything else) where the user clicks. It is very simple code in the RichEdit OnClick handler extracting text and checking if hyperlink. – fpiette Sep 11 '20 at 07:23
  • @fpiette I highly comment the approach outlined by Remy in the dupe. It has the huge benefit of standing on top of the native functionality. – David Heffernan Sep 11 '20 at 07:56
  • @DavidHeffernan But this approach requires to modify the text and find links upfront to give the the attributes of a link. You cannot just open a RTF file and let the user interact with it. – fpiette Sep 11 '20 at 11:17
  • Originally, RichEdits ONLY supported "hyperlinks" that could only be opened in IE. I guess that interface mechanism has been relaxed so this restriction is no longer in effect, but it would be good to have a post that discusses the general case of hyperlinks in RichEdit controls. – David Sep 11 '20 at 16:42

0 Answers0