WebHtmlContainer issue

I'm trying to add html to a WebHtmlContainer at runtime.

I set the ID of a span on the page to "MyContainer". I bind to the WebHtmlContainer by setting the ElementID to "MyContainer".

I'm my WebHttpRequest.OnResponse, I create my html code based on the response from my rest service.

Here's some code from the WebHttpRequestResponse:

  frmListings := TFrmListings.CreateNew(HostPanel.ElementID, nil);
  frmListings.Caption := '';
  window.location.hash := 'listings';
  await(TfrmListings, frmListings.Load());
  frmListings.ListingsContainer.HTML.Add(html.text);

While debugging, I can see that my html TStringlist has html code. However, when I debug the Listings page in the browser, the html code never makes it to the page.

My hunch is that my approach here is all wrong. Any direction to another approach would be great.

John

I do not understand how your code is in connection with what you say about TWebHTMLContainer. TFrmListings can't be of the type TWebHTMLContainer as this class has no Load() method.
It rather looks like a form and if so, do you somehow want to load the HTML for the form in a TWebHTMLContainer that is used on this form? I'm not sure what you want to reach with this?

The last line of my code references the WebHtmlContainer (ListingsContainer). The container is located on the frmListings form, and is referenced here as frmListings.ListingsContainer.

I'm not understanding the purpose of loading the form's HTML content again in a WebHTMLContainer on this same form?

Okay, let me try to be more clear.

  // frmListings is a TWebForm
  frmListings := TFrmListings.CreateNew(HostPanel.ElementID, nil);
  frmListings.Caption := '';
  window.location.hash := 'listings';
  // wait for frmListings (a TWebForm) to load
  await(TfrmListings, frmListings.Load());
  // ListingsContainer is a TWebHtmlContainer located on frmLisings (TWebForm)
  // html.text is some HTML. Add to WebHtmlContainer (ListingsContainer) 
  frmListings.ListingsContainer.HTML.Add(html.text);

I retested this here with the Demo : Demo\Basics\MultiForm. I added a TWebHTMLContainer to the 2nd form and changed the code to:

// init control after loading
newform.frm2Edit.Text := WebEdit1.Text;
newform.WebHTMLContainer1.HTML.Text := 'Hello world';

and this shows the text in the TWebHTMLContainer.
Please compare with / copy this approach.

Yes, I did something similar in testing. The issue is, I think, is that I'm loading the form async. I figured out a solution.. I had to set a public form string variable on the form I'm loading before loading, and populate the WebHTMLContainer in the form's WebFormShow event. Here's the code:

frmListings := TFrmListings.CreateNew(HostPanel.ElementID, nil);
frmListings.Caption := '';
window.location.hash := 'listings';
frmListings.ContainerHTML := html.text;
await(TfrmListings, frmListings.Load());

procedure TfrmListings.WebFormShow(Sender: TObject);
begin
WebHTMLContainer1.HTML.Add(ContainerHtml);
end;

This seems to work fine.

Thanks for reporting. It could be that before, you were trying to set the HTML text before the control was created.