11 Vote

Delphi: Set up a link to a homepage from a delphi application

Tutorial by Delphian | 2012-08-12 at 02:21

Sometimes, it is a good idea to set up a link to a homepage in a Windows application. In this tutorial, I will show you how to do that in Delphi.

We are using a API function from the ShellApi for that and we want to style a label that it will look like it is a link.

The Label with the Link

To make our TLabel looking like a link, we are using the following settings, that can also be adjusted by using the Object Inspector:

Label1.Caption := 'www.sttmedia.com';
Label1.Font.Color := clBlue;
Label1.Font.Style := [fsUnderline];
Label1.Cursor := crHandPoint;

The caption of the label is the Internet adress, we want to call. The font should be blue and underlined and if we are moving our mouse over the label, the cursor should be changed to a hand.

The Code

We have to add "ShellApi" to "uses" and we are using the following code:

uses 
   ShellApi, ...

procedure TForm1.Label1Click(Sender: TObject);
begin
  ShellExecute(Application.Handle, 'open', PChar(Label1.Caption), 
    nil, nil, SW_ShowNormal);
end;

If we click on our label, the standard browser will be opened with the website written in the caption of the label.

ReplyPositiveNegative

About the Author

AvatarThe author has not added a profile short description yet.
Show Profile

 

Related Topics

Delphi: Rename Folder

Tutorial | 0 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.