[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 305
  • Last Modified:

Internet Explorer Component: Get source code.

I'm using delphi 5 "new" internet explorer component. (Just a wrapper for MS explorer's activex control). I'd like to have the source code of the current html document. Is this possible, an example would be nice.
0
leon321
Asked:
leon321
  • 2
1 Solution
 
simonetCommented:
The code above was first posted by inthe (Barry) in the question :

http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=10219724 

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,StdCtrls, OleCtrls, SHDocVw_TLB,ActiveX;

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

var
  Form1: TForm1;

const
  SOURCE = 2;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
Begin
Webbrowser1.OleObject.Navigate('www.experts-exchange.com');
end;

procedure TForm1.Button2Click(Sender: TObject);
const
  CGID_WebBrowser: TGUID = '{ED016940-BD5B-11cf-BA4E-00C04FD70816}';
var
  CmdTarget : IOleCommandTarget;
  vaIn, vaOut : OleVariant;
  PtrGUID : PGUID;
 begin
  New(PtrGUID);
  PtrGUID^ := CGID_WebBrowser;
  if WebBrowser1.Document <> nil then
    try
      WebBrowser1.Document.QueryInterface(IOleCommandTarget, CmdTarget);
      if CmdTarget <> nil then
        try
          CmdTarget.Exec( PtrGUID, SOURCE, 0, vaIn, vaOut);
        finally
          CmdTarget._Release;
        end;
    except
      // Nothing
    end;
  Dispose(PtrGUID);

end;
 end.

****************

Here's another way to do it (saving it to a file):

procedure TForm1.Button2Click(Sender: TObject);
var
Persist : IPersistFile;
Document : IHTMLDocument2;
b : longbool;
begin
   Document :=Webbrowser1.Document as IHTMLDocument2;
   Persist := Document as IPersistFile;
   Persist.Save('C:\temp.htm',b);
   memo1.lines.loadfromfile('C:\temp.htm');
end;

Yours,

Alex
0
 
leon321Author Commented:
Thanks Alex,

The first example is not usefull for me, because it displays notepad.

The second one is Ok!
Delphi5 does not know IHTMLDocument2 (maybe it's in SHDocVw_TLB, but not in delphi5 somewere). So I used IPersistFile in stead and saved it to a file.

Do you know a nice way to get it in an delphi stream or string, so I don't have to use a file? (Got to learn myself some ole!)

0
 
simonetCommented:
Sorry, Leon. I don't know how to place the HTML text directly into a stream, but I'll look into it and, it I have some luck, I'll get back to you.

Yours,

Alex
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now