My problem is that Form2 won't show inside Form1 panel in the code below:
procedure TForm1.WebButton1Click(Sender: TObject);
var
LResult: integer;
newform: TForm2;
begin
newform := TForm2.Create(Self);
newform.Caption := 'test form';
newform.Parent := WebPanel1; // this is the problem it doesn't work
newform.Popup := false;
// used to manage Back button handling to close subform
window.location.hash := 'main';
// load file HTML template + controls
await(TForm2, newform.Load());
// init controls values after loading
newform.WebLabel1.caption := newform.WebLabel1.caption + ' is working!';
try
// excute form and wait for close
LResult := await(TModalResult, newform.Execute);
WebLabel1.Caption := WebLabel1.Caption + newform.ModalResult.ToString();
ShowMessage('Form 2 is closed!');
finally
newform.Free;
end;
end;
I'm trying to use VCL way to achieve this so far but the form is not displaying inside the panel!
newform.Parent := WebPanel1; // this is the problem it doesn't work no error messages
another approach is:
frm := TForm2.CreateNew(WebPanel1.ElementID, nil);
Which is working perfectly however it will not act as a modal like my code above to give back a result.
My goal is to display Form2 inside a panel in Form1 and wait for the user to close it so it can return a result to Form1 (a simple modal form way).
any way to do this please?
Visible
property of your second form toTrue
? By default when you create additional forms in Delphi theirVisibility
property is always set toFalse
. So either set your second form's theVisible
property toTrue
at design-time or callnewForm.Show;
. But definitely don't callnewForm.ShowModal
when this form is shown within other form as you will block receiving any windows messages to it since they need to go through parent form message que which is currently being blocked by modality of your second form.WebCore
, but it seems you are missing anewform.show;
after setting the forms parent. I also do not undestand why you need to call 'newform.Popup := false;'LResult := await(TModalResult, newform.Execute);
as mentioned above waits for the form till closes then save the return message in a LResult. also setting for Visibility doesn't affect anything herenewform.show
as again `LResult := await(TModalResult, newform.Execute);' will display the form but the problem it is not inside the panel, it is covering the whole page!