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.
leon321Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.