How to identify urls after setting EM_AUTOURLDETECT to TRichEdit?

I am trying to implement URL discovery for the TRichEdit component using the EM_AUTOURLDETECT message.
I have a problem with the following code

procedure TForm1.Button1Click(Sender: TObject);
var Mask: Word;
begin
  Mask := SendMessage(Handle, EM_GETEVENTMASK, 0, 0);
  SendMessage(Handle, EM_SETEVENTMASK, 0, Mask or ENM_LINK);
  SendMessage(Handle, EM_AUTOURLDETECT, Integer(True), 0);
end;

This works, but I have to change the text of TRichEdit after these settings to find that it detects URLs in already written text. And this problem, because my TRichEdit is in ReadOnly mode when applying this function.

What should I do after executing this code to make TRichEdit detect URLs in already written text?
I looked at the documentation , but there is no mention of anything like that.

thank

+5
source share
1

() . EM_AUTOURLDETECT , () .

procedure TForm1.Button1Click(Sender: TObject);
var
  EventMask: Word;
  CharRange: TCharRange;
begin
  EventMask := SendMessage(RichEdit1.Handle, EM_GETEVENTMASK, 0, 0);
  SendMessage(RichEdit1.Handle, EM_SETEVENTMASK, 0, EventMask or ENM_LINK);
  SendMessage(RichEdit1.Handle, EM_AUTOURLDETECT, WPARAM(True), 0);
  SendMessage(RichEdit1.Handle, EM_EXGETSEL, 0, LPARAM(@CharRange));
  SendMessage(RichEdit1.Handle, WM_SETTEXT, 0, LPARAM(RichEdit1.Text));
  SendMessage(RichEdit1.Handle, EM_EXSETSEL, 0, LPARAM(@CharRange));
end;
+4

All Articles