Search code examples
pascallazarusfreepascal

How to make link button in Lazarus?


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;

Solution

  • 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.