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.
feupAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
intheConnect With a Mentor Commented:
cheers
0
 
intheCommented:
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
0
 
feupAuthor Commented:
If you tell me how to get the HTML code of the page, I'll give you the points.


Thanks
0
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

 
intheCommented:
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;

0
 
feupAuthor Commented:
great!

Make an answer, and the points are yours.


Thanks

Joao
0
 
feupAuthor Commented:
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.

0
 
intheCommented:
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
0
 
feupAuthor Commented:
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 :))
0
All Courses

From novice to tech pro — start learning today.