Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

Getting the HTML code for eny page displayed in iExplorer window ??

Hi,
I want to access to a document currently dislayed in iExplorer browser. I don't want to use any delphi components accept API's. is it possible within dephi ?
0
niso123
Asked:
niso123
1 Solution
 
smotCommented:
Hi,

This code works for me:

uses
  MSHTML_TLB, ActiveX;


function GetHTMLCode(WB: IWebbrowser2; ACode: TStrings): Boolean;
var
  ps: IPersistStreamInit;
  s: string;
  ss: TStringStream;
  sa: IStream;
begin
  ps := WB.document as IPersistStreamInit;
  s := '';
  ss := TStringStream.Create(s);
  try
    sa:= TStreamAdapter.Create(ss, soReference) as IStream;
    Result := Succeeded(ps.Save(sa, Bool(True)));
    if Result then ACode.Add(ss.Datastring);
  finally
    ss.Free;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  ShellWindow: IShellWindows;
  WB: IWebbrowser2;
  spDisp: IDispatch;
  IDoc1: IHTMLDocument2;
  k: Integer;
begin
  ShellWindow := CoShellWindows.Create;
  // get the running instance of Internet Explorer
  for k := 0 to ShellWindow.Count do
  begin
    spDisp := ShellWindow.Item(k);
    if spDisp = nil then Continue;
    // QueryInterface determines if an interface can be used with an object
    spDisp.QueryInterface(iWebBrowser2, WB);
    if WB <> nil then
    begin
      WB.Document.QueryInterface(IHTMLDocument2, iDoc1);
      if iDoc1 <> nil then
      begin
        WB := ShellWindow.Item(k) as IWebbrowser2;
        begin
          // Add HTML Code to Memo
          Memo1.Lines.Add('****************************************');
          Memo1.Lines.Add(WB.LocationURL);
          Memo1.Lines.Add('****************************************');
          GetHTMLCode(WB, Memo1.Lines);
        end;
      end;
    end;
  end;
end;
0
 
CleanupPingCommented:
niso123:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
kacorretiredCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:
       to accept smot's answer
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Merry Christmas and happy new year!

kacor
EE Cleanup Volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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