Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms





   
 


Hyperlink


When we surf on internet, we often found the text, usually with the blue color, underlined, and if we click on the text, it will open other document, other web site, or if the text is someone's e-mail address, it will open default messaging application such as Outlook Express. The text is called hyperlink.

Pic1. Hyperlink


Here we won't discuss how to create an hyperlink in an HTML's document. This page is provided to help you to make a label to function as an hyperlink in Delphi programming.

To create an hyperlink in a form, you can use
ShellExecute function which is provided by the unit ShellAPI.pas.

[Note: The unit ShellAPI.pas is 'associated' with the Windows dynamic link library named Shell32.dll]

This function is declared as follows :

HINSTANCE ShellExecute(
HWND hwnd, LPCTSTR lpOperation, LPCTSTR lpFile, LPTSTR lpParameters, LPCTSTR lpDirectory, INT nShowCmd);


The hWnd parameter specifies the parent window, the lpOperation parameter pointer to a null-terminated string that specifies the operation to perform. The following operation strings are valid:

  • "open" The function opens the file specified by lpFile. The file can be an executable file or a document file.
  • "print" The function prints the file specified by lpFile. The file should be a document file. If the file is an executable file, the function opens the file, as if "open" had been specified.

The third parameter, lpFile, pointer to a null-terminated string that specifies the file to open or print. The function can open an executable file or a document file. The function can print a document file. For the lpParameters parameter, if lpFile specifies an executable file, lpParameters is a pointer to a null-terminated string that specifies parameters to be passed to the application, and if lpFile specifies a document file, lpParameters should be NULL.

The lpDirectory parameter pointer to a null-terminated string that specifies the default directory. And the last parameter, nShowCmd, should be zero if lpFile specifies a document file. If lpFile specifies an executable file, nShowCmd specifies how the application is to be shown when it is opened. I suggest you to reference to the help file Win32.hlp for detail.

Don't be confused with those parameters. You don't have to fill all those parameters to create an hyperlink in a form.

As an example, if you had a label captioned with
'send mail to me', and you wanted to function this label as an hyperlink to your e-mail address, then you should use the following code:

ShellExecute(0,'open','mailto:[put your e-mail address here..','','',SW_NORMAL);

And if you wanted to create an hyperlink to open a web site address (www.kutu2000.com for example), then the code should looked like this:

ShellExecute(0,'open','www.kutu2000.com','','',SW_NORMAL);

It's easy. Isn't it ?

Now, to make you fully understand about this topic, below please find the complete listing how to create an hyperlink in a form. For your attention, since Delphi doesn't automatically recognize a label functioned as an hyperlink, you have to change the font color and give it an underline yourself, and also you should change the Cursor property into crHandPoint.


// *******************************************************
// Unit Name : UnLink.pas
// Author : Irhantoro E
// *******************************************************
// Programmed to demontrate the use of ShellExecute function
// provided by unit ShellAPI.pas
// *******************************************************

unit UnLink;

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ShellAPI, StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Bevel1: TBevel;
Label3: TLabel;
procedure Label1Click(Sender: TObject);
procedure Label2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Label1Click(Sender: TObject);
begin
ShellExecute(0,'open','mailto:irhantoro.eko@SoftHome.net','','',SW_NORMAL);
end;

procedure TForm1.Label2Click(Sender: TObject);
begin
ShellExecute(0,'open','http://irhan.netfirms.com','','',SW_NORMAL);
end;

end.

// end of file

References:

· Help file, Win32 Developer's References
· Charles Calvert, Delphi Unleashed, Sams Publishing

 
 

This article is written by Irhantoro E
email:
irhantoro.eko@softhome.net
Website:
http://irhan.netfirms.com


 




Main | My Resume | Articles | Photos | Links