简体   繁体   English

如何将HTML字符串加载到Firemonkey TWebBrowser中?

[英]How can I load an HTML string into a Firemonkey TWebBrowser?

I'm trying to use the Firemonkey TWebBrowser to load some HTML that is generated at runtime. 我正在尝试使用Firemonkey TWebBrowser加载运行时生成的一些HTML。 The HTML is a Delphi string. HTML是一个Delphi字符串。

I've looked at some code from: http://delphi.about.com/cs/adptips2004/a/bltip0104_4.htm 我看过以下代码: http : //delphi.about.com/cs/adptips2004/a/bltip0104_4.htm

procedure WBLoadHTML(WebBrowser: TWebBrowser; HTMLCode: string) ;
var
   sl: TStringList;
   ms: TMemoryStream;
begin
   WebBrowser.Navigate('about:blank') ;
   while WebBrowser.ReadyState < READYSTATE_INTERACTIVE do
     Application.ProcessMessages;

   if Assigned(WebBrowser.Document) then begin
     sl := TStringList.Create;
     try
       ms := TMemoryStream.Create;
       try
         sl.Text := HTMLCode;
         sl.SaveToStream(ms) ;
         ms.Seek(0, 0) ;
         (WebBrowser.Document as IPersistStreamInit).Load(TStreamAdapter.Create(ms)) ;
       finally
         ms.Free;
       end;
     finally
       sl.Free;
     end;
   end;
end;

procedure TForm1.FormCreate(Sender: TObject) ;
var
  sHTML : string;
begin
  sHTML := '<a href="http://delphi.about.com">GOTO</a>' +
           '<b>About Delphi Programming</b>';
  WBLoadHTML(WebBrowser1,sHTML) ;
end;

but this appears to be designed for a VCL application which is incompatible with Firemonkey TWebBrowser . 但这似乎是为与Firemonkey TWebBrowser不兼容的VCL应用程序设计的。

How can I achieve the same thing as this code example but using the Firemonkey control? 我如何使用Firemonkey控件实现与此代码示例相同的功能?

使用WebBrowser LoadFromStrings方法。

You could implement this functionality in a DLL...detail and downloadable example here . 您可以在DLL ...中实现此功能,详细信息可在此处下载示例

Another option is to consider this open-source TWebBrowserEx project . 另一个选择是考虑这个开源TWebBrowserEx项目 It actually will use the platform's normal web browser functionality. 实际上,它将使用平台的常规Web浏览器功能。 However, in the case of Windows it means that in your FMX project you will be using the VCL for the web browser support.. .which may or may not have unintended effects. 但是,对于Windows,这意味着在FMX项目中,您将使用VCL来支持Web浏览器。.这可能会或可能不会产生意外的影响。

This class provide WebBrowser for All-Platform FireMonkey Applications. 此类为全平台FireMonkey应用程序提供WebBrowser。

Platform => Component 平台=>组件

  • Windows => IWebBrowser(IE) Windows => IWebBrowser(IE)
  • OS X => WebView(Safari) OS X => WebView(Safari)
  • iOS => WebView iOS => WebView
  • Android => WebView Android => WebView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM