Link to home
Start Free TrialLog in
Avatar of sharons
sharons

asked on

Detecting URLs in TMemo

I am using a TMemo in a mail client. I would like to implement the function of having URLs in the TMemo become links that can be clicked to launch web browser.
Avatar of BlackMan
BlackMan

If you want to use TMemo, I think you have some hard work to do. Instead you can switch to RichEdit v2, it has a AutoURLDetect property. There is an example on www.torry.com on how to use it.

What identifies a URL? Just the "http://"?
Avatar of sharons

ASKER

Thank you. I tried to find that example in Torry's but could not find it. Is it in Examples or is it with a component ?
You can find the example under "Components / Edit,Memos #2" with the name TRichEdit98.
Direct download is www.torry.com/vcl/edits/richedit98.zip

who is sharons?
(your profile doesn't tell too much)
BlackMan's comment's it.

cheers,
Black Death.
You can of course do it the 'hard' way, which would be :

procedure findurl(sender: Tobject);
const url = 'http://';
var urlpos : array[1..100,1..100] of boolean;
for i := 1 to memo.lines do
begin
  for j := 1 to length(memo.lines[i]) - 6 do
  begin
    if copy(memo.lines[i],j,length(url)) = url then urlpos[j, i] := true;
    memo2.lines.add('url found on line ' + inttostr(i) + ' at position + ' inttostr(j));
  end;
end;

You can cut pieces out of there to make it a one line function, which might be easier to find.
Avatar of sharons

ASKER

Thank you all. I used Blackmans suggestion to use TRichEditV2 from Torry and it works great. One thing I did not include in the description of the problems is that I also want to be able to click on these links and invoke the Web Browser. TRichEditV2 does just that.  So I guess the points should go to BlackMan.
ASKER CERTIFIED SOLUTION
Avatar of BlackMan
BlackMan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial