Recent

Author Topic: Displaying html-pages with ipro iphtmlpanel?  (Read 15447 times)

Pancratius

  • New Member
  • *
  • Posts: 14
Displaying html-pages with ipro iphtmlpanel?
« on: May 31, 2014, 07:22:28 pm »
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.

« Last Edit: May 31, 2014, 07:38:34 pm by Pancratius »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Displaying html-pages with ipro iphtmlpanel?
« Reply #1 on: May 31, 2014, 08:13:34 pm »
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

  • New Member
  • *
  • Posts: 14
Re: Displaying html-pages with ipro iphtmlpanel?
« Reply #2 on: May 31, 2014, 11:57:32 pm »
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

  • Hero Member
  • *****
  • Posts: 5368
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Pancratius

  • New Member
  • *
  • Posts: 14
Re: Displaying html-pages with ipro iphtmlpanel?
« Reply #4 on: June 02, 2014, 09:12:57 pm »
http://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

  • Hero Member
  • *****
  • Posts: 5368
Re: Displaying html-pages with ipro iphtmlpanel?
« Reply #5 on: June 02, 2014, 10:58:16 pm »
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.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

quickes

  • Newbie
  • Posts: 2
Re: Displaying html-pages with ipro iphtmlpanel?
« Reply #6 on: June 10, 2014, 11:58:42 pm »
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

  • New Member
  • *
  • Posts: 14
Re: Displaying html-pages with ipro iphtmlpanel?
« Reply #7 on: June 12, 2014, 09:04:22 pm »
try 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

  • New Member
  • *
  • Posts: 14
Re: Displaying html-pages with ipro iphtmlpanel?
« Reply #8 on: March 24, 2015, 01:40:34 am »
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.
« Last Edit: March 24, 2015, 01:54:51 am by Pancratius »

wch409

  • Newbie
  • Posts: 3
Re: Displaying html-pages with ipro iphtmlpanel?
« Reply #9 on: March 30, 2015, 03:49:19 pm »
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.
...

Congratulations! 
I was wondering if you would post all of your unit  it took to make this work?

Thanks,
wch409

Pancratius

  • New Member
  • *
  • Posts: 14
Re: Displaying html-pages with ipro iphtmlpanel?
« Reply #10 on: April 05, 2015, 04:02:58 pm »
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.
...

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.
                                       
« Last Edit: April 05, 2015, 04:05:52 pm by Pancratius »

wch409

  • Newbie
  • Posts: 3
Re: Displaying html-pages with ipro iphtmlpanel?
« Reply #11 on: April 10, 2015, 07:09:12 pm »
Thanks for posting the code.  I'll play with it and see if I can learn more.


wch409

  • Newbie
  • Posts: 3
Re: Displaying html-pages with ipro iphtmlpanel?
« Reply #12 on: April 10, 2015, 07:29:15 pm »
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

  • New Member
  • *
  • Posts: 14
Re: Displaying html-pages with ipro iphtmlpanel?
« Reply #13 on: April 13, 2015, 05:03:28 pm »
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
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.

 

TinyPortal © 2005-2018