Displaying html-pages with ipro iphtmlpanel?
lazarus / 38-Networking and Web Programming
----------------------------------------------------------------------
Pancratius · 2014-05-31 17:22
Hi, this is my first posting. I'm trying to write a webbrowser using
Synapse's Httpsend component and Turbopower's IpHtmlPanel but i cannot
make it work. I searched the internet but to no avail. I can receive
headers with the following code: Code: [Select]procedure
TForm1.GetHeaderButtonClick(Sender: TObject);
var HTTP : THTTPSend;
list : TStringlist;
Header : TStringlist;
begin
Header := TStringlist.Create;
HTTP := THTTPSend.Create;
list := TStringlist.Create;
Header.Add('Accept: text/html');
HTTP.Headers.AddStrings(Header);
try
if not HTTP.HTTPMethod('GET', Edit1.Text) then
begin
ShowMessage('Error' + sLineBreak + IntToStr(HTTP.ResultCode));
end
else
begin
Memo2.Lines.Clear;
Memo2.Lines.Append(IntToStr(HTTP.ResultCode) + ' ' +
HTTP.ResultString);
Memo2.Lines.Append(HTTP.Headers.Text);
list.LoadFromStream(HTTP.Document);
Memo2.Lines.Append(list.Text);
end;
finally
HTTP.Free;
Header.Free;
list.Free;
end;
end;
And the following code produces raw HTML-code:
Code: [Select]procedure TForm1.Button1Click(Sender: TObject);
var strings : TStringlist;
begin
with THTTPSend.Create do
begin
if HTTPMethod('GET', Edit1.Text) then
try
strings := TStringlist.Create;
strings.LoadFromStream(Document);
Memo1.Lines.AddStrings(strings);
strings.Free;
except
Application.MessageBox('Cannot display', 'Error', 0)
end;
Free;
end;
But the code below, using IpHtmlPanel, produces only a black window.
Code:
Code: [Select]procedure TForm1.Button1Click(Sender: TObject);
var s : TStringlist;
IpHtml : TIpHtml;
ms : TMemoryStream;
StrList : TStringList;
begin
with THTTPSend.Create do
begin
if HTTPMethod('GET', Edit1.Text) then
try
StrList := TStringList.Create;
//StrList.Text:= HTMLString; <- Something is wrong here!
ms := TMemoryStream.Create;
StrList.SaveToStream(ms);
ms.Position:= 0;
IpHtml := TIpHtml.Create;
IpHtml.LoadFromStream(ms);
IpHTMLPanel1.SetHtml(IpHtml);
ms.Free;
s := TStringlist.Create;
s.LoadFromStream(Document);
Memo1.Lines.AddStrings(s);
s.Free;
except
Application.MessageBox('Cannot display', 'Error', 0)
end;
Free;
end;
end;
I have realised that i have to use Lazarus IpFileDataProvider but i
don't understand how to use it.
The code below is fetched from the Internet and shows an example of
how to use it , but I get a compilation error trying to run it.
TIpFormDataEntity is the culprit. As far as I understand,
TIpFormDataEntity is used when making a POST to a web server. Where
have I made mistakes in the codes ?Have anyone of you an example of a
working webbrowser code using IPro's components.
Pardon my compilatory coding efforts.
----------------------------------------------------------------------
howardpc · 2014-05-31 18:13
You can see working examples of the use of TIpFileDataProvider in
Lazarus in the
...\lazarus\examples\htmlhelp_ipro\
folder in the two units
htmlhelp2viewer.pas (line17, etc)
and
htmlhelp2unit2.pas (line 48, etc)
----------------------------------------------------------------------
Pancratius · 2014-05-31 21:57
Thanks for a quick reply, but simply saying "look at the demos"
doesn't help me at all. The demos does not show me how to access
www.google.com for instance. I don't know what to make of your answer.
Either you are a code savvy person who think IPro is a piece of cake
and you actually have written working codes on how to access webpages
on the Internet but wont tell others how to do it, or you have not. I
don't know. But I do know that I, and many people like me, needs
hands-on coding samples in order to understand IPros components. The
demos are just not helpful.
If a car has a flat tyre nobody is helped by someone telling them
that they need to tap rubber from rubber tree in the Brazilian
rainforest, and then mold a tyre. No offence, please.
----------------------------------------------------------------------
taazz · 2014-06-01 04:11
http://wiki.lazarus.freepascal.org/fpbrowser
----------------------------------------------------------------------
Pancratius · 2014-06-02 19:12
Quote from: taazz on June 01, 2014, 06:11:45
amhttp://wiki.lazarus.freepascal.org/fpbrowser
Thanks, the link seems to be what I am looking for. As far as I
understand the relevant files are viewer_ipro.pas and pageloader.pas.
----------------------------------------------------------------------
taazz · 2014-06-02 20:58
I don't know, I only know that it exists and can be used as an example
if needed. I never had the need to look for help yet though.
----------------------------------------------------------------------
quickes · 2014-06-10 21:58
try this (it's work for me)
Code: [Select] htmlNews.SetHtmlFromStr(HttpDataNews.Result);
htmlNews.Refresh;
Patch IpHtml.pas for national languages (ru and e.t.c)
Code: [Select]IpHtml.pas
procedure TIpHtml.Parse;
{$IFDEF IP_LAZARUS}
var
ch1,ch2,ch3: AnsiChar;
{$ENDIF}
begin
Getmem(TokenStringBuf, 65536);
{!!.01}
try
{!!.01}
CharSP := 0;
ListLevel := 0;
StartPos := CharStream.Position;
{$IFDEF IP_LAZARUS}
FDocCharset := 'UTF-8';//'ISO-8859-1'; <---- change this
----------------------------------------------------------------------
Pancratius · 2014-06-12 19:04
Quote from: quickes on June 10, 2014, 11:58:42 pmtry this (it's work
for me)
Code: [Select] htmlNews.SetHtmlFromStr(HttpDataNews.Result);
htmlNews.Refresh;
Hi quickies, thanks a lot. I have tried your code and changed the
names in it in order for me to understand it. This is how it looks
now:
Code: [Select]IpHTMLPanel1.SetHtmlFromStr(IpHtml. ... ); <-
Something's wrong here!
IPHTMLPanel1.Refresh;
When I type "IpHthmPanel1.SetHtmlFromStr(IpHtml" and the dot, but
then I don't get the option the chose the "Result"-method. I get lots
of other events but not the "Result". Why haven't I that event? Is
Result something you have declared your self?
----------------------------------------------------------------------
Pancratius · 2015-03-24 00:40
Holy shit, I have somehow managed to write a webbrowser. It's crude
and primitive and does nothing else other than display a webpage as
long as there are no images. The program cannot display images, but
crashes if there are any.
This is the part that works: Code: [Select]if
httpsend.HTTPMethod('GET', Edit1.Text) then
begin
IpFileDataProvider1.DoGetStream(Edit1.Text);
IpHtmlPanel1.SetHtmlFromStream(httpsend.Document);
end;
Well, now I would like the webrowser to display images. I have tried
many different approaches and the code below is what I believe to be
almost correct. When I run the program I get an error message saying
"EInvalidGraphic Unknown picture format".
I guess I have to add something in the uses section but I'm not sure
of what. Can someone tell me what's wrong with the code and what is
missing?
Code: [Select]if httpsend.HTTPMethod('GET', Edit1.Text) then
begin
//html.OnGetImageX:= @HTMLGetImageX;
//html.LoadFromStream(ms);
IpFileDataProvider1.DoGetStream(Edit1.Text);
//IpFileDataProvider1.DoGetImage(IpHtmlNode,Edit1.Text, picture);
Picture.LoadFromStream(httpsend.Document);
IpHtmlPanel1.SetHtmlFromStream(httpsend.Document);
Label1.Caption:= httpsend.TargetHost;
Turbo Powers PDF-helpfile mentions the DoGetImage procedure. You have
to supply the procedure with some variables, of which is TIpHtmlNode.
How do I determine what value there should be that variable? I hope
you understand my not so clear question.
----------------------------------------------------------------------
wch409 · 2015-03-30 13:49
Quote from: Pancratius on March 24, 2015, 01:40:34 amHoly shit, I have
somehow managed to write a webbrowser. It's crude and primitive and
does nothing else other than display a webpage as long as there are no
images. The program cannot display images, but crashes if there are
any.
...
Congratulations!
I was wondering if you would post all of your unit it took to make
this work?
Thanks,
wch409
----------------------------------------------------------------------
Pancratius · 2015-04-05 14:02
Quote from: wch409 on March 30, 2015, 03:49:19 pmQuote from:
Pancratius on March 24, 2015, 01:40:34 amHoly shit, I have somehow
managed to write a webbrowser. It's crude and primitive and does
nothing else other than display a webpage as long as there are no
images. The program cannot display images, but crashes if there are
any.
...
Congratulations!
I was wondering if you would post all of your unit it took to make
this work?
Thanks,
wch409
Sure thing, baby. The program works only as long as there are no
images on the web page. You can even follow links to other web pages
with no images. If you find out how to display images with
iphtmlpanel, please let me know. Try the code with tis webpage:
http://web.mit.edu/sciric/www/ocs/
I think I will leave Turbo IPro now. The documentation on how to use
it is scarse.
Code: [Select]unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, IpHtml, Ipfilebroker, Forms, Controls,
Graphics,
Dialogs, StdCtrls, httpsend;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
IpFileDataProvider1: TIpFileDataProvider;
IpHtmlPanel1: TIpHtmlPanel;
procedure Button1Click(Sender: TObject);
procedure IpHtmlPanel1HotClick(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var httpsend : THTTPSend;
begin
httpsend := THTTPSend.Create;
try
if httpsend.HTTPMethod('GET', Edit1.Text) then
begin
IpFileDataProvider1.DoGetStream(Edit1.Text);
IpHtmlPanel1.SetHtmlFromStream(httpsend.Document);
end;
finally
httpsend.Free;
end;
end;
procedure TForm1.IpHtmlPanel1HotClick(Sender: TObject);
var NodeA : TIpHtmlNodeA;
link : string;
httpsend : THTTPsend;
begin
httpsend := THTTPSend.Create;
NodeA := TIpHtmlNodeA(IpHtmlPanel1.HotNode);
link := NodeA.HRef;
if httpsend.HTTPMethod('GET', link) then
begin
IpFileDataProvider1.DoGetStream(link);
IpHtmlPanel1.SetHtmlFromStream(httpsend.Document);
end;
end;
end.
----------------------------------------------------------------------
wch409 · 2015-04-10 17:09
Thanks for posting the code. I'll play with it and see if I can learn
more.
----------------------------------------------------------------------
wch409 · 2015-04-10 17:29
Here are some sites that I found useful to build a working web
browser. I still haven't got it to do everything (such as pull
html/xml), but do feel making progress.
http://forum.lazarus.freepascal.org/index.php?topic=15352.0
http://lazplanet.blogspot.com/2013/10/browser-in-lazarus-with-gecko-
pt1.html
----------------------------------------------------------------------
Pancratius · 2015-04-13 15:03
Quote from: wch409 on April 10, 2015, 07:29:15 pmHere are some sites
that I found useful to build a working web browser. I still haven't
got it to do everything (such as pull html/xml), but do feel making
progress.
http://forum.lazarus.freepascal.org/index.php?topic=15352.0
http://lazplanet.blogspot.com/2013/10/browser-in-lazarus-with-gecko-
pt1.html
Hi, wch409. I've found a quite recent posting from a forum member:
http://forum.lazarus.freepascal.org/index.php?topic=26296.0
I don't really understand what DOM and nodes mean, but his
documentation on how lazbro works, will definitly make it easier to
comprehend the nuts and bolts behind a web browser.
I've installed gecko but I don't think it provides any challenge. It's
to easy to use it.