Groups | Search | Server Info | Login | Register


Groups > comp.lang.pascal.delphi.misc > #255

Memo/Richedit with Hyperlink capabilities, web aware

From Sven Parnol <sven.parnol@none.net.ch>
Newsgroups comp.lang.pascal.delphi.misc
Subject Memo/Richedit with Hyperlink capabilities, web aware
Date 2012-04-02 18:56 +0200
Organization SP
Message-ID <jlclo7$fjc$1@speranza.aioe.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.pascal.delphi.misc | Previous | NextNext in thread | Find similar


Thread

Memo/Richedit with Hyperlink capabilities, web aware Sven Parnol <sven.parnol@none.net.ch> - 2012-04-02 18:56 +0200
  Re: Memo/Richedit with Hyperlink capabilities, web aware "P E Schoen" <paul@peschoen.com> - 2012-05-26 20:38 -0400
    Re: Memo/Richedit with Hyperlink capabilities, web aware Jamie <jamie_ka1lpa_not_valid_after_ka1lpa_@charter.net> - 2012-05-26 21:13 -0400

csiph-web