?
Solved

Open Web browser with local html document

Posted on 2004-11-24
8
Medium Priority
?
520 Views
Last Modified: 2010-04-05
Hi Ppl

Just a quick one, how do I trigger the default web browser with a preprepared html document from within an application?

TIA
0
Comment
Question by:andru
8 Comments
 
LVL 2

Expert Comment

by:Ratje
ID: 12669124
u could try :


shellexecute(handle,'open','YourHTMFileHere',nil,nil,SW_SHOW);
0
 
LVL 11

Accepted Solution

by:
calinutz earned 200 total points
ID: 12669421


procedure ViewDocument(DocumentURL: string; ReuseBrowserWindow: Boolean);
var
  BrowserPath : string;
begin
  if ReuseBrowserWindow then
   Shellexecute(0, 'Open', PChar(DocumentURL), nil, nil, SW_SHOWNORMAL)
  else
  begin
    with TRegistry.Create do
    begin
      try
        RootKey := HKEY_CLASSES_ROOT;
        OpenKey('\htmlfile\shell\open\command', False);
        try
          BrowserPath := ReadString('');
        except
          MessageDlg('The default browser could not be found.', mtError, [mbOK], 0);
          Exit;
        end;
        CloseKey;
      finally
        Free;
      end;
    end;
    BrowserPath := Copy(BrowserPath, Pos('"', BrowserPath) + 1, Length(BrowserPath));
    BrowserPath := Copy(BrowserPath, 1, Pos('"', BrowserPath) - 1);
    ShellExecute(0, 'Open', PChar(BrowserPath), PChar(DocumentURL), nil, SW_SHOWNORMAL);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ViewDocument('www.google.com', False);
//or
  ViewDocument('C:\webpage.htm', False);

end;
0
 

Author Comment

by:andru
ID: 12669490
Err, how do I call shellexecute? It aint exactly a Delphi method.

TIA
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 12669614
add

uses ShellAPI
0
 

Author Comment

by:andru
ID: 12671069
K, here is the code I'm using

procedure Tmap_form.trefach_menu_itemClick(
      Sender: TObject);
var
  s:string;
  p:pansichar;
begin
  s:=application_path+'trefach\trefach.htm'+#0;
  p:=@s;
  shellexecute(handle,'open',p,nil,nil,SW_SHOW);
end;

where am I going wrong?

TIA
0
 
LVL 2

Expert Comment

by:Ratje
ID: 12672800
why not make s a PChar

s : PChar;
s:=application_path+'trefach\trefach.htm';
shellexecute(handle,'open',s,nil,nil,SW_SHOW);

and make sure that s contains

application_path\trefach\trefach.htm

and not

application_pathtrefach\trefach.htm

Works for me
0
 
LVL 17

Expert Comment

by:geobul
ID: 12672894
procedure Tmap_form.trefach_menu_itemClick(
     Sender: TObject);
var
  s:string;
begin
  s:=application_path+'trefach\trefach.htm';
  shellexecute(handle,'open',PChar(s),nil,nil,SW_SHOWNORMAL);
end;
0
 

Author Comment

by:andru
ID: 12677109
Err, application_path already has a backslash at the end.

TIA
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…
Get the source code for a fully functional Access application shell with several popular security features that Access VBA application developers desire, but find difficult or impossible to figure out how to code. You get the source code for managi…
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question