How to start default browser with a URL(with spaces and #) for a local file? Delphi

后端 未结 6 1268
天涯浪人
天涯浪人 2021-01-21 06:15

I want to open a local HTML file in the default browser.

For example: Default Browser is Mozilla Firefox.

The file to be opened: C:\\My Custom Path\\New Folde

6条回答
  •  無奈伤痛
    2021-01-21 06:24

    i think this is better way:

    function OpenHtmlFile(FileAdr :string):Boolean;
    var
      vTempFile :string;
      vData     :TStrings;
    begin
      Result:= False;
      vTempFile:= GetTempFolder + '_tmphtmlrunfile.html';
      vData:= TStringList.Create;
      vData.Text:= '';
      try
        try
          vData.SaveToFile(vTempFile, TEncoding.UTF8);
        finally
          vData.Free;
        end;
        ShellExecute(Handle,
                 'open',
                 PChar(vTempFile),
                 nil,
                 nil,
                 SW_SHOWNORMAL);
        Result:= True;
      except
      end;
    end;
    

提交回复
热议问题