Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delphi newbie: How to make links in a form

Status
Not open for further replies.

albn

Programmer
Oct 31, 2003
5
US
I am making a simple text editor in Delphi 2006. The project is almost done, but I am having trouble getting clickable links to open a defualt browser to a specified webpage. I know there has to be an easy way to do this, but I have not found answers elsewhere.

Here is the code:

unit thanks;

interface

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

type
TForm4 = class(TForm)
StaticText1: TStaticText;
StaticText2: TStaticText;
StaticText3: TStaticText;
btnOk: TBitBtn;
VPLSite: TLabel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
procedure VPLSiteClick(Sender: TObject);
procedure btnOkClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form4: TForm4;

implementation
uses
ShellAPI;

{$R *.dfm}

procedure TForm4.VPLSiteClick(Sender: TObject);
var s : string;
begin
s := (Sender as TLabel).Caption;
ShellExecute(GetDesktopWindow(), 'open', PChar(s), nil, nil, SW_SHOWNORMAL);
end;

procedure TForm4.btnOkClick(Sender: TObject);
begin
Close;
end;

end.

where could I be going wrong? Thank you in advance.
 
Don't know if this will help. I am a bit of a newbie.

You don't have the shellapi in your uses for the shellexecute command.

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls, ExtCtrls, shellapi, Buttons;


on a button 1 click

ShellExecute(0,'open',PChar('
seems to open IE for me.
 
Thanks, I will give that a try. According to ripping code from Dev CPP, the roginal code did not have a ShellAPI in the uses, but I will try it.

Thanks.
 
You are having a compilation error or a runtime error, please? And what one?

buho (A).
 
There is a simple freeware component that can handle this for you and also create email links. Do a google for AKurl2


[red]GNBM 4th Feb[/red] More on and other neat UK stuff at forum1091
Steve: Delphi a feersum engin indeed.
 
No, I am not getting any errors. That is what is driving me nuts. :(

I will just look at the example again from Dev CPP.
 
Please, check the ShellExecute return.

r := ShellExecute(Handle, 'open', PChar(s), nil, nil, SW_SHOWNORMAL);

if r <= 32 you got an error, look it up in MSDN and/or tell us here.

buho (A).

 
That was the error. I got it working. Thanks buho. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top