Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Posting HTML source to an object Memo or ... 1

Status
Not open for further replies.

WayneStev

Programmer
Joined
Jan 3, 2006
Messages
21
Location
US
Code:
At this point I am developing a browser using Delphi 7.0 and TWwbBrowser this works fine.. The problum I would like to be able to also post the text html as a souce in an other oplect RICHEDIT or MEMO anyn way some I need to get the lines of source of the web page to post as I go from one site to any other..  What I need to knoiw can this be done and I need eathe some sample code how to make this happer..  HELP PLEASE

 
---------------
Lets hack some code :)
---------------

Code:
uses MSHTML_TLB;    [b][COLOR=red]// <----  See notes  <-------[/color][/b] 

[COLOR=red]//----[/color]
function TForm1.DocCompleted(pDisp1 : IDispatch; 
                             pDisp2 : IDispatch) : boolean;
  var
    SIU, BIU : IUnknown;
  begin
    [COLOR=red]{Document [b]really[/b] ended (all frames handled) if SIU = BIU. 
    Search MSDN for an explanation.} [/color]
    SIU := pDisp1 as IUnknown;
    BIU := pDisp2 as IUnknown;
    DocCompleted := SIU = BIU;
  end;

[COLOR=red]//----[/color]
function TForm1.GetHTML(Browser : TWebBrowser) : AnsiString;
  var
    Doc   : IHTMLDocument2;
    Col   : IHTMLelementCollection;
    Ele   : IHTMLelement;
  begin
    GetHTML := '';
    [COLOR=red]{Wait for the browser to end.}[/color]
    while Browser.Busy do Sleep(10);
    [COLOR=red]{Get the document.}[/color]
    try
      Doc := Browser.Document as IHTMLDocument2;
    except
      Doc := nil;
    end;
    [COLOR=red]{If we got a doc, get the HTML.}[/color]
    if Doc <> nil
      then
        begin
          Col := Doc.All.Tags('HTML') as IHTMLelementCollection;
          Ele := Col.Item(0, '') as IHTMLelement;
          if Ele <> nil
            then GetHTML := Ele.OuterHTML;
        end;
  end;

[COLOR=red]//---- Browser event[/color]
procedure TForm1.WebBrowser1DocumentComplete(Sender     : TObject;
                                             const pDisp: IDispatch;
                                             var URL    : OleVariant);
  var
    HTML : AnsiString;
  begin
    [COLOR=red]{Lets be sure all frames are handled.}[/color]
    if DocCompleted(WebBrowser1.ControlInterface, pDisp)
      then
        begin
          [COLOR=red]{Get the HTML text (if any) and show it.}[/color]
          HTML := GetHTML(WebBrowser1);
          if HTML <> ''
            then Memo1.Text := HTML;
        end;
  end;


Notes: you can get MSHTML_TLB.PAS from MSHTML.DLL (in the system folder) using TLIBIMP.EXE (in the Delphi binary folder). Google for instructions, you'll find plenty.

buho (A).
 
Thanks for the star :).

buho (A).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top