This is a question from the Forum. The sample code is as follows, mainly to understand the Document Object.
// ------ This forum does not support delphi code styles 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.html text; End;
End. |