Recent

Author Topic: Using TFrameBrowser  (Read 7516 times)

eric

  • Sr. Member
  • ****
  • Posts: 267
Using TFrameBrowser
« on: May 22, 2013, 09:03:05 pm »
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(<Remote URL>);
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

  • Sr. Member
  • ****
  • Posts: 267
Re: Using TFrameBrowser
« Reply #1 on: May 23, 2013, 04:59:25 pm »
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(<Remote URL>);
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

  • Hero Member
  • *****
  • Posts: 1290
Re: Using TFrameBrowser
« Reply #2 on: May 24, 2013, 07:04:19 am »
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
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

eric

  • Sr. Member
  • ****
  • Posts: 267
Re: Using TFrameBrowser
« Reply #3 on: May 24, 2013, 08:46:38 am »
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

  • New Member
  • *
  • Posts: 14
Re: Using TFrameBrowser
« Reply #4 on: June 02, 2014, 09:09:45 pm »
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(<Remote URL>);
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.

 

TinyPortal © 2005-2018