FORM上放置一个按钮和WEBBrowser控件,uses mshtml则下面程序通过.
procedure TForm1.Button1Click(Sender: TObject);
begin
   WebBrowser1.Navigate('c:\a.htm');
end;procedure TForm1.loaded(ASender: TObject; const pDisp: IDispatch;
  var URL: OleVariant);
begin
   hdoc2:=webbrowser1.Document as IHTMLDocument2;
   ShowMessage(hdoc2.body.innerHTML);
end;在VB里利用createDocumentFromUrl能够直接打开文档的.如
Private Doc As New MSHTML.HTMLDocument
Private iDoc As MSHTML.HTMLDocument
Set iDoc = Doc.createDocumentFromUrl(FileName, vbNullString)
请问DELPHI里如何也不借助WebBrowser直接象上面的VB一样打开一个文档?

解决方案 »

  1.   

    VB不懂。所以不是很明白你的意思。如果你是想以记事本方式打开网页源码。用Delphi可以这样写:WinExec('notepad c:\a.htm',1);方法很多,这只是最简单的的方法。这个代码在VB和VC上都可以用的。
      

  2.   

    我想打开来进行HTML分析呀。原来在VB下利用IHTMLDocument2进行分析,现在改为DELPHI分析。
    当然借助TWEBBrowser可以打开IHTMLDocument2,但我想在VB中不借助其他的能行的,DELPHI怎样也可以。
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,MSHTML, ActiveX,comobj, OleCtrls, SHDocVw, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        WebBrowser1: TWebBrowser;
        procedure Button1Click(Sender: TObject);
        procedure WebBrowser1DocumentComplete(Sender: TObject;
          const pDisp: IDispatch; var URL: OleVariant);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}function GetHtml(const WebBrowser:TWebBrowser): string;
    const
      BufSize = $10000;
    var
      Size: Int64;
      Stream: IStream;
      hHTMLText: HGLOBAL;
      psi: IPersistStreamInit;
    begin
      if not Assigned(WebBrowser.Document) then Exit;  OleCheck(WebBrowser.Document.QueryInterface(IPersistStreamInit, psi));
      try
        hHTMLText := GlobalAlloc(GPTR, BufSize);
        if 0 = hHTMLText then RaiseLastWin32Error;    OleCheck(CreateStreamOnHGlobal(hHTMLText, True, Stream));
        try
          OleCheck(psi.Save(Stream, False));      Size := StrLen(PChar(hHTMLText));
          SetLength(Result, Size);
          CopyMemory(PChar(Result), Pointer(hHTMLText), Size);
        finally
          Stream := nil;
        end;
      finally
        psi := nil;
      end;
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    self.WebBrowser1.Navigate('www.google.cn');
    end;procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
      const pDisp: IDispatch; var URL: OleVariant);
    begin
    showmessage(gethtml(self.WebBrowser1));
    end;end.
      

  4.   

    还不是用了webbrowse控件,我想不用呀