這個問題來自論壇提問,示例代碼如下,主要是要了解Document對象
//------這個論壇居然不支持delphi代碼樣式
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, StdCtrls,mshtml;
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
Button1: TButton;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
WebBrowser1.Navigate('www.csdn.net');
end;
procedure TForm1.Button1Click(Sender: TObject);
var doc:mshtml.IHTMLDocument2;
var select:mshtml.IHTMLTxtRange;
begin
doc:= self.WebBrowser1.Document as mshtml.IHTMLDocument2;
select:=doc.selection.createRange() as mshtml.IHTMLTxtRange;
memo1.Text:= select.htmlText;
end;
end.