Return procedure for a form hosted in a control

I tried to create a subform in a HTMLDiv of a main form, and it works perfectly :

frm := TSubForm1.CreateNew(HTMLDiv1.ElementID, @AfterCreate);

But how to add a procedure called when this subform is closed or destroyed? For popup forms, the following code exists :

newform := TForm2.CreateNew(@AfterCreate);

But for a form hosted in a control, I can't find any solution.

I'd like to have a "close" button in the subform. And after closing this subform, the mainform can execute code to create another subform of another type in the same place.

Hi Leroy,
Declare a procedure in your mainform and call it from close button of the subform

procedure TfrmMain.OpenNewSubForm;
  newsubform := TfrmNewSubForm.CreateNew(HTMLDiv1.ElementID, @AfterCreate);

Thanks for your reply.

But how to call this procedure from the subform? frmMain.OpenNewSubForm doesn't work.

If the MainForm unit is in the uses list of your subform interface or implementation it should work.
What compiler error or runtime exception do you get?

I tried to use this code in a new project, and it's working perfectly.

It seems that there is a bug in my project, not coming from my code. I've a runtime error in Chrome (see attachment) which mention a unit u_inscription.pas, which is in the project but not in the uses of my Mainform and Subform. WebButton1 is the quit button of my Subform. I can't understand a link to this unit u_inscription.pas.


Since the unit u_inscription.pas is in the project it will go into the genarated project JS, may be it has an autocreated form and may be the elements ids getting mixed up. Is WebButton1 connected to an elementId on the html file?

I mean may be you have same html element id attributes on those forms so that the wrong event is triggering.