Path: csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Sven Parnol Newsgroups: comp.lang.pascal.delphi.misc Subject: Memo/Richedit with Hyperlink capabilities, web aware Date: Mon, 02 Apr 2012 18:56:57 +0200 Organization: SP Lines: 74 Message-ID: NNTP-Posting-Host: qwoXhxUYCwVZNqxiVN6keQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.pascal.delphi.misc:255 My client asked if I could add hyperlink capability to TDBMemo control which is connected to their own customer database. So the idea being that they could freely add text and www-hyperlinks, the Control would recognize Hyperlinks and when clicked, open them in Default Browser. My first impression was that that could be done. But not easily. Dealing with plain text and old TDBMemo controls, I thought it would be like starting to add hyperlink capability to 16-bit Notepad application. These were the links I found first: http://www.scalabium.com/faq/dct0146.htm http://delphi.about.com/od/vclwriteenhance/l/aa051804a.htm The About.com.tip is a bit tricky and complicated. The Scalabium sample almost does what is needed. But as with About.com tip, also their TRichEdit control needs to be placed directly on the Form. If you place TRichEdit control for instance on TPanel, the hyperlinks just stop working. At this phase it started to look a bit complicated to get TRichEdit to react on any Control. Finally I found a tip telling that some hypertext capability was also maybe in Rxlib Library. Bingo, there they were! This useful RxLib library has been installed on my machine for almost 10 years, but I had not noticed this earlier. Both TRichEdit and database aware TDBRichEdit replacement, with built in web/hypertext capability: TRxRichEdit TRxDBRichEdit procedure TForm1.RxDBRichEdit1URLClick(Sender: TObject; begin ShellExecute(Handle, 'open', PChar(URLText), 0, 0, SW_SHOWNORMAL); end; The nice thing is that the text does not need to be saved as RichText format. These controls recognize links like http://www.google.com or mailto:bill.gates@microsoft.com straight from plain text. Or from Memo type plain text Database field. So I just need to replace old TDbMemo control with TRxDBRichEdit controls, and I get nicely looking, modern hyperlink capable functionality, that works also with all the existing data. Here's one more enchancement, that I made myself. These controls are even a bit too eager to react on mouse clicks over www-links. If you would just like to edit the Memo text, and try to place cursor inside hyperlink area the control reacts right away and opens the link. To avoid this, I use this code: procedure TForm1.RxDBRichEdit1URLClick(Sender: TObject; begin FURLText := URLText; // Save the clicked www-link. end; procedure TEdCustForm.RxRichEd1DblClick(Sender: TObject); // This way Web links open only when you double click the link. begin if FURLText <> '' then begin ShellExecute(Handle, 'open', PChar(URLText), 0, 0, SW_SHOWNORMAL); FURLText:=''; end; end; --- That's it. The final code is not rocket science. Yet it took me almost two days to find all this. And to get the hyperlink clicks and Memo editing to work without hassle. I wrote this article because the working solution was so simple after all. Yet the hyperlink capability this brings to TDbMemo fields looks very nice. Hopefully this saves someone else that two days I had to take. Some tip pay back for the Delphi community:) -SP