Using TFrameBrowser lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- eric · 2013-05-22 19:03 Could someone please help me to get started with using TFrameBrowser to display a remote web page. I've looked at various examples and demos, but they're all quite complicated and it's difficult to reduce them to the essentials. I've got as far as this: Code: [Select]unit Unit1; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, FileUtil, Forms, Controls, Graphics,   Dialogs, StdCtrls, ExtCtrls, Buttons, FramBrwz, htmlview; type   { TForm1 }   TForm1 = class(TForm)     BitBtn1: TBitBtn;     FrameBrowser1: TFrameBrowser;     procedure BitBtn1Click(Sender: TObject);     procedure FrameBrowser1GetPostRequestEx(Sender: TObject; IsGet: boolean;       const URL, Query, EncType, Referer: string; Reload: boolean;       var NewURL: string; var DocType: ThtmlFileType; var Stream: TMemoryStream       );   private     { private declarations }   public     { public declarations }   end; var   Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.BitBtn1Click(Sender: TObject); begin    FrameBrowser1.LoadURL(); end; procedure TForm1.FrameBrowser1GetPostRequestEx(Sender: TObject; IsGet: boolean;   const URL, Query, EncType, Referer: string; Reload: boolean;   var NewURL: string; var DocType: ThtmlFileType; var Stream: TMemoryStream); begin end; end. I presume that the data is in the stream, but what do I do with it? ---------------------------------------------------------------------- eric · 2013-05-23 14:59 If anyone is interested, I've worked out the basics. I use httpsend (part of Synapse) to download the web page as a stream, and copy it to the TFrameBrowser stream. The following code works with a very simple page: Code: [Select]unit Unit1; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, FileUtil, Forms, Controls, Graphics,   Dialogs, StdCtrls, ExtCtrls, Buttons, FramBrwz, htmlview, httpsend; type   { TForm1 }   TForm1 = class(TForm)     BitBtn1: TBitBtn;     FrameBrowser1: TFrameBrowser;     procedure BitBtn1Click(Sender: TObject);     procedure FrameBrowser1GetPostRequestEx(Sender: TObject; IsGet: boolean;       const URL, Query, EncType, Referer: string; Reload: boolean;       var NewURL: string; var DocType: ThtmlFileType; var Stream: TMemoryStream       );   private     { private declarations }   public     { public declarations }   end; var   Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.BitBtn1Click(Sender: TObject); begin   FrameBrowser1.LoadURL(); end; procedure TForm1.FrameBrowser1GetPostRequestEx(Sender: TObject; IsGet: boolean;   const URL, Query, EncType, Referer: string; Reload: boolean;   var NewURL: string; var DocType: ThtmlFileType; var Stream: TMemoryStream); var   S: string;   N: Integer;   HTTPClient: THTTPsend; begin   S := URL;   N := Pos('http://', S);   if N = 1 then  //Remove prefix   begin     S := S[8..Length(S)];   end;   Stream := TMemoryStream.Create;   HTTPClient := THTTPSend.Create;   HTTPClient.Timeout := 5000;   try     if HTTPClient.HTTPMethod('GET', S) then     begin       Stream.CopyFrom(HTTPClient.Document, HTTPClient.Document.Size);     end;   finally     HTTPClient.Free;   end; end; end. ---------------------------------------------------------------------- Jurassic Pork · 2013-05-24 05:04 hello eric, are you on windows , linux , both, others ? what kind of web pages would you display ? don't forget that now often web pages have javascript scripts. For this you need an "embedded" browser  : geckport or chromiumembedded  for example. If you are on windows it is more easy with activex and internet explorer. Friendly, J.P ---------------------------------------------------------------------- eric · 2013-05-24 06:46 Hello JP I develop on Linux, but I build for both Linux and Windows. For my purpose here I only needed very basic browser capabilities, to enable my program to collect some data from a specially written page on my own website. The solution above is working well now. ---------------------------------------------------------------------- Pancratius · 2014-06-02 19:09 Quote from: eric on May 23, 2013, 04:59:25 pmIf anyone is interested, I've worked out the basics. I use httpsend (part of Synapse) to download the web page as a stream, and copy it to the TFrameBrowser stream. The following code works with a very simple page: Code: [Select]unit Unit1; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, FileUtil, Forms, Controls, Graphics,   Dialogs, StdCtrls, ExtCtrls, Buttons, FramBrwz, htmlview, httpsend; type   { TForm1 }   TForm1 = class(TForm)     BitBtn1: TBitBtn;     FrameBrowser1: TFrameBrowser;     procedure BitBtn1Click(Sender: TObject);     procedure FrameBrowser1GetPostRequestEx(Sender: TObject; IsGet: boolean;       const URL, Query, EncType, Referer: string; Reload: boolean;       var NewURL: string; var DocType: ThtmlFileType; var Stream: TMemoryStream       );   private     { private declarations }   public     { public declarations }   end; var   Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.BitBtn1Click(Sender: TObject); begin   FrameBrowser1.LoadURL(); end; procedure TForm1.FrameBrowser1GetPostRequestEx(Sender: TObject; IsGet: boolean;   const URL, Query, EncType, Referer: string; Reload: boolean;   var NewURL: string; var DocType: ThtmlFileType; var Stream: TMemoryStream); var   S: string;   N: Integer;   HTTPClient: THTTPsend; begin   S := URL;   N := Pos('http://', S);   if N = 1 then  //Remove prefix   begin     S := S[8..Length(S)];   end;   Stream := TMemoryStream.Create;   HTTPClient := THTTPSend.Create;   HTTPClient.Timeout := 5000;   try     if HTTPClient.HTTPMethod('GET', S) then     begin       Stream.CopyFrom(HTTPClient.Document, HTTPClient.Document.Size);     end;   finally     HTTPClient.Free;   end; end; end.The code does not work. TFrameBrowser has to do something with the returning stream generated by the HTTPclient.