Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-09

How do I get the default path and filename for the user's HTML browser???

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Peter E Williams

Hi All,

I am writing a procedure called OpenHTMLFile. It works fine with HTML_Browser_file (which is the command to run) set to 'firefox' on my Linux Ubuntu 10.04 system.

My question is this... what do I need to change to make HTML_Browser_file default to the default application (path and filename) to open a html file e.g. I want it to be the path and application filename of ANY computer's HTML browser. I assume that in this day of modern computing that it would be safe to assume that the user has some kind of html browsing software whether it be: Firefox, Chrome, Internet Explorer, or whatever it is that Macs use ... sorry for my ignorance, but I am not a Mac user, so I am no up with the latest browser for Macs.

I want to do this:
    Proc.CommandLine := HTML_Browser_file;
// e.g. it will now be 'firefox'
    if Proc.CommandLine is a valid application then
      Proc.CommandLine := Whatever_is_the_default_HTML_Browser;
From Memo1 after run of project1 and call to Button1Click:

File HTML_2_Open "test1.html" does not exists. Opening browser with blank filename.
Process.CommandLine is: "firefox"

uses Process;
[...]
procedure TForm1.OpenHTMLFile(HTML_Browser_file, HTML_2_Open : String);
var
  x : integer;
  Proc : TProcess;
  S : String;
  I : integer;
begin
  { // this code not used!!!
  S := Application.ExeName;
  // hack for Mac
  I := Pos('.app/Contents/MacOS/', S);
  if (I > 0) then
    S := Copy(S,1, I+3);
  }
  Proc := TProcess.Create(nil);
  try
    // Proc.CommandLine := '/Applications/MyApp.app';
    Proc.CommandLine := HTML_Browser_file;
    if not fileExists( HTML_2_Open ) then
    begin
      memo1.lines.add( 'File HTML_2_Open "' + HTML_2_Open + '" does not
exists. Opening browser with blank filename.' );
      HTML_2_Open := '';
    end
    else
      Proc.CommandLine := Proc.CommandLine + ' ' + HTML_2_Open;
    memo1.lines.add( 'Process.CommandLine is: "' + Proc.CommandLine +
'"');
    PRoc.Options := Proc.Options + [poWaitOnExit];
    Proc.CommandLine := Proc.CommandLine;
    PRoc.Execute;
  finally
    Proc.free;
  end;
end; { OpenHTMLFile }
{---------------------------------------------------------}
procedure TForm1.Button1Click(Sender: TObject);
const
  Default_HTML_Browser_file = 'firefox';
var
  HTML_Browser_file, HTML_2_Open : String;
begin
  HTML_Browser_file := Default_HTML_Browser_file;
  HTML_2_Open := 'test1.html';
  OpenHTMLFile(HTML_Browser_file, HTML_2_Open);
end;

Best Regards,
PEW
Hobart, Tasmania, Australia

Proudly developing Quality Cross Platform Open Source Games Since 1970 with a Commodore PET 4016 with 16 KRAM http://pews-freeware-games.org (<--- brand new)

Reply by email

Michael Van Canneyt
to Peter E Williams

There is no failsafe way. It really depends on the user, distribution.

My solution would be:
- Let user select one
- If none was selected, search a few of the default browsers in the PATH.

Michael.

Peter E Williams wrote 94 lines
Hi All, I am writing a procedure called OpenHTMLFile. It works fine with HTML_Browser_file (which is the command to run) set to 'firefox' on my Linux Ubuntu 10.04 system. My question is this... what do I need to change to make HTML_Browser_file default to the default application (path and filename) to open a html file e.g. I want it to be the path and application filename of ANY computer's HTML browser. I assume that in this day of modern computing that it would be safe to assume that the user has some kind of html browsing software whether it be: Firefox, Chrome, Internet Explorer, or whatever it is that Macs use ... sorry for my ignorance, but I am not a Mac user, so I am no up with the latest browser for Macs. I want to do this: Proc.CommandLine := HTML_Browser_file; // e.g. it will now be 'firefox' if Proc.CommandLine is a valid application then Proc.CommandLine := Whatever_is_the_default_HTML_Browser; > From Memo1 after run of project1 and call to Button1Click: File HTML_2_Open "test1.html" does not exists. Opening browser with blank filename. Process.CommandLine is: "firefox" uses Process; [...] procedure TForm1.OpenHTMLFile(HTML_Browser_file, HTML_2_Open : String); var x : integer; Proc : TProcess; S : String; I : integer; begin { // this code not used!!! S := Application.ExeName; // hack for Mac I := Pos('.app/Contents/MacOS/', S); if (I > 0) then S := Copy(S,1, I+3); } Proc := TProcess.Create(nil); try // Proc.CommandLine := '/Applications/MyApp.app'; Proc.CommandLine := HTML_Browser_file; if not fileExists( HTML_2_Open ) then begin memo1.lines.add( 'File HTML_2_Open "' + HTML_2_Open + '" does not exists. Opening browser with blank filename.' ); HTML_2_Open := ''; end else Proc.CommandLine := Proc.CommandLine + ' ' + HTML_2_Open; memo1.lines.add( 'Process.CommandLine is: "' + Proc.CommandLine + '"'); PRoc.Options := Proc.Options + [poWaitOnExit]; Proc.CommandLine := Proc.CommandLine; PRoc.Execute; finally Proc.free; end; end; { OpenHTMLFile } {---------------------------------------------------------} procedure TForm1.Button1Click(Sender: TObject); const Default_HTML_Browser_file = 'firefox'; var HTML_Browser_file, HTML_2_Open : String; begin HTML_Browser_file := Default_HTML_Browser_file; HTML_2_Open := 'test1.html'; OpenHTMLFile(HTML_Browser_file, HTML_2_Open); end; Best Regards, PEW Hobart, Tasmania, Australia -- Proudly developing Quality Cross Platform Open Source Games Since 1970 with a Commodore PET 4016 with 16 KRAM http://pews-freeware-games.org (<--- brand new) -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Sven Barth
to Michael Van Canneyt
Michael Van Canneyt wrote 9 lines
There is no failsafe way. It really depends on the user, distribution. My solution would be: - Let user select one - If none was selected, search a few of the default browsers in the PATH. Michael.

While Michael's advice is valid you might want to try the functions "FindDefaultBrowser" and "OpenURL" in unit LCLIntf. But I don't know how failsafe they are.

Regards,
Sven

Reply by email