Link to home
Start Free TrialLog in
Avatar of feup
feup

asked on

read the webbrowser component window!

Imagine I browse a page with a text content.

How can I (for example), pass the text to a memo component, in order to read it?

thanks.
Avatar of inthe
inthe

there are 2 ways ,either by saving the webbrowser text to file then loading it into the memo using loadfromfile() or the easier way is to do this:

procedure TForm1.Button1Click(Sender: TObject);
begin
opendialog1.execute;
webbrowser1.oleobject.navigate(opendialog1.filename);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
 vInput,vOutput,cInput,Coutput : OleVariant;
begin
 WebBrowser1.ExecWB(OLECMDID_SELECTALL,0,vInput,vOutput);
 WebBrowser1.ExecWB(OLECMDID_COPY,0,cInput,cOutput);
 Webbrowser1.refresh;
 memo1.SetFocus;
 memo1.pastefromclipboard;
 end;

Regards Barry
Avatar of feup

ASKER

If you tell me how to get the HTML code of the page, I'll give you the points.


Thanks
add to uses
  MSHTML_TLB; {imported with dhtmledit control}


procedure TForm1.Button1Click(Sender: TObject);
var
Doc :  IHtmlDocument2 ;
begin
Doc := Webbrowser1.Document as IHtmlDocument2;
Memo1.Clear;
Memo1.lines.add(trim(doc.body.innerText));
{can be either innerhtml /outerhtml / innertext / outertext}
end;

Avatar of feup

ASKER

great!

Make an answer, and the points are yours.


Thanks

Joao
ASKER CERTIFIED SOLUTION
Avatar of inthe
inthe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of feup

ASKER

Hi inthe.

Could you please help on a doubt?

- Whi do I get an error on the line of the copy, saying that my webbrowser component is not registered as a drop target?

What is the component DHTML?

How do I copy the text to a file?

thanks, and sorry for asking this after I have given you the points.

1:
about the first error either something is wrong in the code you are calling or it is using a different declaration of some function you are using.are you putting MSHTML_TLB and ActiveX in the uses clause?
also add to the bottom of your unit:


initialization
  OleInitialize(nil);

finalization
  OleUninitialize;

end.

2:
in delphi on the component menu click "import activeX" and in the box that pops up select  "DHTMLEdit control for ie5" (or is it "microsoft html object library"?)(well try them both) and click install ,this will then install the components on the activeX tab of your components tab and create some units(one of them will create MSHTML_TLB.pas in your delphi\imports directory).
have a look at the other activeX's as well ,as there are many more that you can import to get components on the activex tab...

3:
to save to file:

uses activeX;

procedure TForm1.Save1Click(Sender: TObject);
var
persist :ipersistfile;
begin
persist := (webbrowser1.document as ipersistfile);
persist.save('c:\a.html',false);
showmessage('page saved as c:\a.html');
end;

hope this solves some troubles,
now im going for some christmas drinks :-))
Regards Barry
Avatar of feup

ASKER

I could now solve my problem, because someone had the same prblem, and with the redirection of the messages (as you answerd it) solved it.


Thanks again

Merry Christmas, and don't drink too much :))