I'm not sure why you added the call await(TFormX, fX.Load);
I have modified the demo under Demo\Basics\FormHosting to mimic this setup with 2 forms and added an extra panel where to host the 2nd created form.
The code to create the forms in the panels;:
procedure TFrmMain.btCreateSubF2Click(Sender: TObject);
begin
frm1 := TSubForm1.CreateNew(WebPanel1.ElementID, nil);
end;
procedure TFrmMain.btCreateSubF2Click(Sender: TObject);
begin
frm2 := TSubForm2.CreateNew(WebPanel1.ElementID, nil);
end;
and I couldn't see anything wrong with the OnCreate event handler set for both forms:
procedure TSubForm1.WebFormCreate(Sender: TObject);
begin
console.log(Self.ClassName+' created.');
end;
procedure TSubForm2.WebFormCreate(Sender: TObject);
begin
console.log(Self.ClassName+' created.');
end;
So, please use the technique as demonstrated in this demo.
I am aware of using callbacks as you have described (that's what I'm currently doing).
I heavily dislike using callbacks to achieve this as I find it makes code harder to read and maintain.
I saw an old topic from years ago where the idea of an async CreateNew was mentioned. Could this be a possibility in the future?
If you do not want to use callbacks, modifying the code in the demo Demo\Basics\MultiForm to show the created form in a WebPanel1 on the form becomes:
var
newform: TForm2;
begin
newform := TForm2.Create(WebPanel1.ElementID);
TAwait.ExecP<TForm2>(newform.Load());
// init control after loading
newform.frm2Edit.Text := WebEdit1.Text;
try
// excute form and wait for close
TAwait.ExecP<TModalResult>(newform.Execute);
ShowMessage('Form 2 closed with new value:"'+newform.frm2Edit.Text+'"');
WebEdit1.Text := newform.frm2Edit.Text;
finally
newform.Free;
end;
end;
so, here you can further modify the created form after the await() on the async load function.