Jump to content
jerik

Load HTML from string in TWebBrowser in Firemonkey

Recommended Posts

procedure TForm2.FormCreate(Sender: TObject);
var
  HTML: string;
begin
  // HTML := TResourceStream.Create(HInstance, 'index', RT_RCDATA).ToString();
  HTML := '<!DOCTYPE html> <html lang="en">' +
    '<head> <meta charset=utf-8>    ' +
    '<title>Test</title><style>body {background:red;}</style>  ' +
    '</head><body>             ' +
    '<h1>TEST</h1> <p>Dette er en tekst!</p> ' +
    '</body> </html>';

  WebBrowser1.LoadFromStrings(HTML, '');

end;

Hi! I have a resourcefile with a HTML-file that I want to load in a FireMonkey TWebBrowser.

 

This is what I have tried and not succeed with:

 

 

Share this post


Link to post
1 hour ago, jerik said:

This is what I have tried and not succeed with:

procedure TForm1.Button1Click(Sender: TObject);
var
  HTML: string;
  BURL: string;
begin
  BURL := '';
  //
  // HTML := TResourceStream.Create(HInstance, 'index', RT_RCDATA).ToString();
  HTML := '<!DOCTYPE html> <html lang="en">' +                     { }
    '<head> <meta charset=utf-8>    ' +                            { }
    '<title>Test</title><style>body {background:red;}</style>  ' + { }
    '</head><body>             ' +                                 { }
    '<h1>TEST</h1> <p>Dette er en tekst!</p> ' +                   { }
    '</body> </html>';
  //
  WebBrowser1.LoadFromStrings(HTML, BURL);
end;

image.png.179322c51024c720bc0b352137900117.png     CONST  X  LITERAL

Edited by programmerdelphi2k
  • Like 1

Share this post


Link to post
2 minutes ago, jerik said:

Bad idea to place it in Form.Create.

as rule, any "critical action" should be in another place... but if strictly necessary use it!

  • Like 2

Share this post


Link to post
On 6/30/2023 at 7:46 PM, jerik said:

Aha! Bad idea to place it in Form.Create.

Thank you!

Yes, there is this problem in the latest versions of Delphi. In the form create event, everything added to the webbrowser is deleted, not only that. It is also deleted when the parent changes.
For example, when you move the WebBrowser parent to an object such as panel2, all the content is gone. I reported this on qualityprortal. Marco cantu wrote that this behavior is normal(!). So correction is not considered.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×