GARANTIR DESCONTO

Fórum webbrowser - exibir pagina cujo codigo fonte esteja no memo! #595808

29/07/2018

0

Ola Pessoa!

como faco para exibir uma pagina no webbrowser delphi cujo codigo fonte html está contido em um memo?

grato,

Adriano
Adriano Pereira

Adriano Pereira

Responder

Posts

30/07/2018

Felipe Morais

Olá, Adriano!

Bem fácil: Segue o dfm do formulário e em seguida o .pas da Unit:

dfm:

object Form1: TForm1
  Left = 1663
  Top = 125
  Width = 602
  Height = 489
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object WebBrowser1: TWebBrowser
    Left = 8
    Top = 16
    Width = 569
    Height = 289
    TabOrder = 0
    ControlData = {
      4C000000CF3A0000DE1D00000000000000000000000000000000000000000000
      000000004C000000000000000000000001000000E0D057007335CF11AE690800
      2B2E126208000000000000004C0000000114020000000000C000000000000046
      8000000000000000000000000000000000000000000000000000000000000000
      00000000000000000100000000000000000000000000000000000000}
  end
  object Memo1: TMemo
    Left = 8
    Top = 320
    Width = 569
    Height = 89
    Lines.Strings = (
      '<html>'
      '  <head>Teste<head>'
      '  <body>'
      '    <p>'
      
        '      Este é um teste de carregamento de HTML de um Memo para um' +
        ' WebBrowser'
      '    </p>'
      '  </body>'
      '</html>')
    TabOrder = 1
  end
  object Button1: TButton
    Left = 8
    Top = 416
    Width = 75
    Height = 25
    Caption = 'Carregar'
    TabOrder = 2
    OnClick = Button1Click
  end
end


Unit.pas:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, OleCtrls, SHDocVw;

type
  TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    Memo1: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  Doc: Variant;
begin
  if not Assigned(WebBrowser1.Document) then
    WebBrowser1.Navigate('about:blank');

  Doc := WebBrowser1.Document;
  Doc.Clear;
  Doc.Write(Memo1.Text);
  Doc.Close;
end;

end.


Espero ter ajudado, abraços!
Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar