How to make link button in Lazarus?

1.2k views Asked by At

I want to make a hyperlink into button. If the button has clicked, the default browser will open the link. I tried it with the Delphi version, but it doesn't work in Lazarus. Here is the code I tried. How do I make it in Lazarus version?

Uses ShellApi

begin
ShellExecute (0, 'Open', 'link website', '', '', SW_SHOWNORMAL);
end;
2

There are 2 answers

0
StrangePapyrus On BEST ANSWER

ShellExecute is something I never really use as I always try to make my programs cross platform. I always use TProcess or RunCommand instead. There's full documentation at the link below, which is pretty good.

http://wiki.freepascal.org/Executing_External_Programs

If you really want to use ShellExecute then I note that in the link it does state the following about initialising COM:

ShellExecute is a standard MS Windows function (ShellApi.h) with good documentation on MSDN (note their remarks about initialising COM if you find the function unreliable).

I hope this helps. If not I will try and help you further.

0
jwdietrich On

The easiest cross-platform compatible way to open a link is provided by the OpenURL function. It is available in the LCLIntf unit, which comes bundled with Lazarus.

Example:

procedure OnClick;
var
  found: boolean;
begin
  found := OpenURL('http://nowhere.loopback.edu');
end;