faqts : Computers : Programming : Languages : Delphi

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

14 of 18 people (78%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

Delphi: Internet: How to execute HTML pages using your favorite browser in Delphi?

Oct 9th, 2003 19:33
Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 06 July 2003 - 04:25 pm -----------------------

---

Delphi: Internet: Webbrowser: HTML: Source: View: How to show the 
source of a HTML page in Delphi?

---

Steps: Overview:

 -use the Windows API 'ShellExecute'

 -together with your favorite browser executable

 -and the name of your HTML page as a parameter

---

Steps: Worked out:

 1. -Open a new application:
     -start your Delphi
      -select from menu option 'File'
       -select from list 'New'
        -select from list 'Application'

 2. -Put a button component on the form:
      -Open the 'Standard' palette
       -double click on icon 'Button'

 3. -Put an editbox component on the form:
     -Open the 'Standard' palette
      -double click on icon 'Edit'

 4. -Apply an event to clicking on the button 1:
     -double click on the 'Button 1' icon on the form

      Note:
      the general format is here:

        ShellExecute( Handle, 'open', '<your favorite browser 
executable filename>', PChar( <the filename parameter> ), nil, 
SW_SHOWNORMAL );

      -type or copy/paste the text:


        ShellExecute( Handle, 'open', 'iexplore', PChar( Edit1.Text ), 
nil, SW_SHOWNORMAL );


 5. -Add in your unit1.pas source code at the 'Uses'

        ShellApi

 6. -To use this:

     1. First type the URL in the editbox1

        e.g. type:

         http://www.allexperts.com

     2. Press button 1 to see this page in your webbrowser
        (here chosen Microsoft Internet Explorer)

 7. -To test this locally (e.g. without Internet connection):

     1. First type the URL in the editbox1

        e.g. type the path to a file you know that exists on your 
computer:

        For example:

         c:\temp\ddd.htm

     2. Press button 1 to see this page in your webbrowser
        (here chosen Microsoft Internet Explorer)

---

This has been tested and worked fine for me
in Delphi 7 and Microsoft Windows XP Professional
[kn, ni, su, 06-07-2003 17:34:04]

---

The steps above will generate the following text in your .pas file:

---

unit Unit1;

interface

uses
  ShellApi,
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, 
Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
 ShellExecute( Handle, 'open', 'iexplore', PChar( Edit1.Text ), nil, 
SW_SHOWNORMAL );
end;

end.

---
---

Internet: see also:

Delphi: Internet: How to execute HTML pages using your favorite 
browser in Delphi?
http://www.faqts.com/knowledge_base/view.phtml/aid/23120/fid/175

---

Simple HTML page scraping with Delphi
http://delphi.about.com/library/weekly/aa062502a.htm

---

Executing and running applications and files from Delphi.
http://delphi.about.com/library/weekly/aa082499.htm

----------------------------------------------------------------------