Is there a function that opens an internet web page? lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- DiCri · 2016-07-21 12:05 Hi Pascal Word, I work with SDL unit. In a program, imagine there is a button and if the player press the button, google chrome starts with a specified url. Is this possible? Thanks! ---------------------------------------------------------------------- howardpc · 2016-07-21 12:33 Add LCLIntf to your uses clause, then use the function Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function OpenURL(AURL: String): Boolean; ---------------------------------------------------------------------- DiCri · 2016-07-21 13:26 Quote from: howardpc on July 21, 2016, 02:33:13 pmAdd LCLIntf to your uses clause, then use the function Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function OpenURL(AURL: String): Boolean; I am using FreePascal so i have not LCLIntf unit.. ---------------------------------------------------------------------- Bart · 2016-07-21 13:35 If on Windows you can use: Code: [Select]  ShellExecuteW(0, nil, PWideChar(TheUrl), nil, nil, SW_SHOWNORMAL). It will launch the default browser (which may or may ot be Chrome), with the specified URL. (TheUrl must be a UnicodeString or WideString). The returnvalue (of type HInst) must be > 32, otherwise the function failed. Bart ---------------------------------------------------------------------- Ñuño_Martínez · 2016-07-21 19:49 Problem with ShellExecute is that it is Windows only. There's no simple way to do it in a cross platform way.  I was looking for something like that, so I read the LCL sources to see how they do it and it's quite complicated.  Each operating system uses a very different way. Linux seems to be the worst case.  It scans different functions and locations to find a webbrowser executable then run it passing the appropriate command-line options. ---------------------------------------------------------------------- wp · 2016-07-21 20:44 TProcess? (http://wiki.freepascal.org/Executing_External_Programs) Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  Process; var  AProcess: TProcess;begin  AProcess := TProcess.Create(nil);  try    AProcess.Executable := 'C:\Program Files (x86)\Mozilla Firefox\firefox.exe';    AProcess.Parameters.Add('somefile.html');    AProcess.Options := AProcess.Options + [poWaitOnExit];    AProcess.Execute;  finally    AProcess.Free;  end; ---------------------------------------------------------------------- Leledumbo · 2016-07-21 22:44 Quote from: Ñuño_Martínez on July 21, 2016, 09:49:32 pmLinux seems to be the worst case.  It scans different functions and locations to find a webbrowser executable then run it passing the appropriate command- line options. Unless you're using a very cryptic distro, you can assume that Linux is XDG compliant. In that case: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i $ xdg-open should suffice. ---------------------------------------------------------------------- Handoko · 2016-07-22 04:29 Quote from: Manu12x on July 21, 2016, 03:26:54 pmQuote from: howardpc on July 21, 2016, 02:33:13 pmAdd LCLIntf to your uses clause, then use the function Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function OpenURL(AURL: String): Boolean; I am using FreePascal so i have not LCLIntf unit.. So use Lazarus instead of FPC. I understand the extra 'fat' some people dislike. But fat can be delicious. Lazarus can really speed up your development a lot. Otherwise, write the function yourself using FPC, you can always look into the code of available solutions. wiki.lazarus.freepascal.org/Webbrowser ---------------------------------------------------------------------- Bart · 2016-07-22 10:41 Quote from: Leledumbo on July 22, 2016, 12:44:38 amUnless you're using a very cryptic distro, you can assume that Linux is XDG compliant. In that case: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i $ xdg-open should suffice. AFAIK that's exactly what LCLIntf.OpenUrl() does on *nix platform. Bart ---------------------------------------------------------------------- Leledumbo · 2016-07-22 12:01 Quote from: Bart on July 22, 2016, 12:41:28 pmAFAIK that's exactly what LCLIntf.OpenUrl() does on *nix platform. Extended to widely known browsers for non-XDG compliant distros: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {%MainUnit ../lclintf.pas} // Locates the default browser associated in the system function FindBrowserExecutable(const ShortFilename: String; out ABrowser: String): Boolean; inline;begin  ABrowser := SearchFileInPath(ShortFilename + GetExeExt, '',                    GetEnvironmentVariableUTF8('PATH'), PathSeparator,                    [sffDontSearchInBasePath]);  Result := (ABrowser <> '');end; const  PredefinedBrowserStrings: array[1..10] of String = (    'xdg-open',  'htmlview',    'firefox',    'mozilla',    'galeon',    'konqueror',  'safari',    'netscape',    'opera',    'iexplore'  ); function FindPredefinedBrowser(out ABrowser, AParams: String): Boolean;var  i: Integer;begin  ABrowser := '';  AParams := '"%s"';  for i := Low(PredefinedBrowserStrings) to High(PredefinedBrowserStrings) do    if FindBrowserExecutable(PredefinedBrowserStrings[i], ABrowser) then Break;  Result := (ABrowser <> '');end; ---------------------------------------------------------------------- Bart · 2016-07-22 22:02 Quote from: Leledumbo on July 22, 2016, 02:01:23 pmQuote from: Bart on July 22, 2016, 12:41:28 pmAFAIK that's exactly what LCLIntf.OpenUrl() does on *nix platform. Extended to widely known browsers for non-XDG compliant distros: I know, take a look at svn log  FWIW: Here is some code that tries to find a default browser in *nix (got (parts of) it from Graeme). Bart