Jump to content
Sign in to follow this  
dummzeuch

A simple way to create an URL label in Delphi

Recommended Posts

An URL label is a TLabel on a form which displays some blue, underlined text which, when clicked with the mouse, opens a web page.

This kind of labels is nothing new in Delphi, I remember using them even back in the 1990s, but they always were a pain in the lower back to create:

  • Write the URL into the caption.
  • Set the font color to blue
  • Set the font to underlined
  • Set the cursor to crHandPoint
  • Write an OnClick event handler that opens the desired URL

Lots of boring and repetitive work and on top of that a Windows API call which I kept forgetting.
This led me to simply not use them. [...]

 

https://blog.dummzeuch.de/2019/04/19/a-simple-way-to-create-an-url-label-in-delphi/

Share this post


Link to post
17 minutes ago, dummzeuch said:

but they always were a pain in the lower back to create

Not really since TLinkLabel was introduced as a standard VCL control in Delphi XE2.

  • Like 2

Share this post


Link to post
4 minutes ago, Uwe Raabe said:

TLinkLabel was introduced as a standard VCL control in Delphi XE2

Goes to show that I spend a lot of time working with old Delphi versions.

  • Haha 1

Share this post


Link to post

Hm, a TLinkLabel seems to have no FocusControl property and I could find no way to actually set an URL that is different from the caption.

(OK, it's in the documentation: It allows HTML code.) But apparently it still does not automatically open the browser but calls the OnLinkClick event, so it solves a completely different problem than my code does.

Share this post


Link to post

TLinkLabel is a wrapper around the Windows SysLink control. It has greater flexibility (f.i. can show a mixture of text and several links, not only one URL, as well as distinguish between a link, a focused link and a visited link) and thus requires a more sophisticated event handling (not every link needs to be opened in a browser).

 

Anyway, my quote was rather related to the list of PITAs than your actual code.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×