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?

52 of 56 people (93%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

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

Oct 15th, 2003 14:12
Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 06 July 2003 - 01:42 pm -----------------------

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

---

Steps: Overview:

 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 another button component on the form:
      -Open the 'Standard' palette
       -double click on icon 'Button'

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

 5. -Put an memobox component on the form:
     -Open the 'Standard' palette
      -double click on icon 'Memo'

 6. -Put a Webbrowser component on the form:
      -Open the 'Internet' palette
       -double click on icon 'Webbrowser'

 7. -Apply an event to clicking on the button 1:
     -double click on the 'Button 1' icon on the form
      -type the text:
        Webbrowser1.Navigate( Edit1.Text );

 8. -Apply an event to clicking on the button 2:
     -double click on the 'Button 2' icon on the form
      -type or copy/paste the text:
        { Internet: source: 
http://www.cpcug.org/user/clemenzi/technical/Databases/Delphi/WebClient
s.html }
        var DOM : variant;
        begin
         DOM := WebBrowser1.Document;
         if Webbrowser1.LocationURL <> '' then begin
          Memo1.Text := DOM.Body.OuterHTML;
         end
         else begin
          ShowMessage('No page available!');
         end;

 9. -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 the webbrowser1

     3. Press button 2 to see the source of this HTML page in memobox1

10. -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 the webbrowser1

     3. Press button 2 to see the source of this HTML page in memobox1

---

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

---

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

---

unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
 Webbrowser1.Navigate( Edit1.Text );
end;

procedure TForm1.Button2Click(Sender: TObject);
 { Internet: source: 
http://www.cpcug.org/user/clemenzi/technical/Databases/Delphi/WebClient
s.html }
 var DOM : variant;
 begin
  DOM := WebBrowser1.Document;
  if Webbrowser1.LocationURL <> '' then begin
   Memo1.Text := DOM.Body.OuterHTML;
  end
  else begin
   ShowMessage('No page available!');
  end;
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/23124/fid/175

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