Recent

Author Topic: [solved] Projects in C:\lazarus\examples - openbrowser  (Read 3715 times)

PeterX

  • Sr. Member
  • ****
  • Posts: 445
[solved] Projects in C:\lazarus\examples - openbrowser
« on: May 12, 2017, 12:59:07 pm »
Interesting way to open the browser  :o
.. if it would work.

By reading GetEnvironmentVariableUTF8('PATH')
in function SearchExecutable()
the program tries to find and start - for example - FIREFOX

Quote
function SearchExecutable(const ShortFilename: string; var Filename: string
  ): boolean;
begin
  Filename:=SearchFileInPath(ShortFilename,'',
                      GetEnvironmentVariableUTF8('PATH'),PathSeparator,[]);
  Result:=Filename<>'';
end;

On my computer, here, Windows 7, the firefox.exe is not (or no more ?) in the Windows' PATH var.

So does the whole example still make sense ?
« Last Edit: May 15, 2017, 02:03:25 pm by PeterX »
usually using latest Lazarus release version with Windows 10 or 11

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Projects in C:\lazarus\examples - openbrowser
« Reply #1 on: May 12, 2017, 01:16:30 pm »
firefox was never in path and it should never be. Selecting start\run and typing firefox in the dialog should open firefox. from a command window (cmd) typing firefox should not start it. Firefox adds it self in "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" registry key. This key is used to find and start the application from the run dialog.
You can use the same settings from a command line using the start command. eg
Code: Text  [Select][+][-]
  1. start firefox
  2.  
this will use the registry as well as the path to find and execute firefox. I'm not user but I think that its an internal command of the windows console application.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

PeterX

  • Sr. Member
  • ****
  • Posts: 445
Re: Projects in C:\lazarus\examples - openbrowser
« Reply #2 on: May 12, 2017, 01:24:30 pm »
Screenshot

usually using latest Lazarus release version with Windows 10 or 11

wp

  • Hero Member
  • *****
  • Posts: 13578
Re: Projects in C:\lazarus\examples - openbrowser
« Reply #3 on: May 12, 2017, 01:26:50 pm »
I am not sure about the intention of this example, and therefore, I will not touch it. The recommended way to open a URL with the system browser is OpenURL(url:string) in LclIntf; there is also a FindDefaultBrowser which does more careful searching than just looking in the path, it could replace the GetBrowser of the sample, but I did not investigate how this would fit into the shell scripts provided.

Probably, the sample is just outdated...
« Last Edit: May 12, 2017, 01:28:58 pm by wp »

PeterX

  • Sr. Member
  • ****
  • Posts: 445
Re: Projects in C:\lazarus\examples - openbrowser
« Reply #4 on: May 12, 2017, 01:42:15 pm »
Probably, the sample is just outdated...

I agree, looks curious, the whole thing.

This is the content of one of the .sh files:
Quote
#!/usr/bin/env bash

firefox -remote "openurl($1)" || firefox $1 &

Is this maybe a UNIX only example ?
usually using latest Lazarus release version with Windows 10 or 11

wp

  • Hero Member
  • *****
  • Posts: 13578
Re: Projects in C:\lazarus\examples - openbrowser
« Reply #5 on: May 12, 2017, 02:11:01 pm »
Is this maybe a UNIX only example ?

Yes, but it can certainly be rewritten as a batch file for Windows.

I asked in the developers mailing list about this sample, the author is still active.

wp

  • Hero Member
  • *****
  • Posts: 13578
Re: Projects in C:\lazarus\examples - openbrowser
« Reply #6 on: May 12, 2017, 03:49:01 pm »
Mattias answered that the example is obsolete, and he has removed it.

PeterX

  • Sr. Member
  • ****
  • Posts: 445
Re: Projects in C:\lazarus\examples - openbrowser
« Reply #7 on: May 12, 2017, 04:01:48 pm »
Cleaned up ..  :)
usually using latest Lazarus release version with Windows 10 or 11

 

TinyPortal © 2005-2018