whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

37 Visitors Online


 
...parse text from a HTML File using IHTMLDocument2?
Autor: EddieShipman
[ Print tip ]  

Tip Rating (68):  
     


// Very easy way to parse text from HTML using IHTMLDocument2.

uses
  
mshtml, ActiveX, ComObj;

procedure TForm1.Button1Click(Sender: TObject);
var
  
IDoc: IHTMLDocument2;
  Strl: TStringList;
  sHTMLFile: string;
  v: Variant;
  Links: IHTMLElementCollection;
  i: Integer;
  Link: IHTMLAnchorElement;
begin
  if 
OpenDialog1.Execute then
  begin
    
sHTMLFile := OpenDialog1.FileName;
    Strl := TStringList.Create;
    try
      
Strl.LoadFromFile(sHTMLFile);
      Idoc := CreateComObject(Class_HTMLDOcument) as IHTMLDocument2;
      try
        
IDoc.designMode := 'on';
        while IDoc.readyState <> 'complete' do
          
Application.ProcessMessages;
        v := VarArrayCreate([0, 0], VarVariant);
        v[0] := Strl.Text;
        IDoc.Write(PSafeArray(System.TVarData(v).VArray));
        IDoc.designMode := 'off';
        while IDoc.readyState <> 'complete' do
          
Application.ProcessMessages;
        Memo1.Lines.Text := IDoc.body.innerText;
      finally
        
IDoc := nil;
      end;
    finally
      
Strl.Free;
    end;
  end;
end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners