Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

ModalResult value changes during closing process

Post Reply
MiMi
Posts: 6
Joined: Tue Oct 12, 2021 10:30 am

ModalResult value changes during closing process

Post by MiMi »

Hello!
I'm using the SimpleBrowser demo (from release 87.0.4280.141)
I've added a form that merely opens the SimpleBrowser form with ShowModal
In TFormSimpleBrowser I've added a button that sets its ModalResult to mrOk
When I press the button, ModalResult is set to mrOk but it is changed during the closing process of SimpleBrowser
Following this sequence:
FormCloseQuery : ModalResult = mrOk
ChromiumWindow1Close : ModalResult = mrNone
FormCloseQuery : ModalResult = mrCancel

Why?
Thanks in advance for any help or tips
User avatar
salvadordf
Posts: 4580
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: ModalResult value changes during closing process

Post by salvadordf »

Hi,

The source code in CEF4Delphi doesn't modify the ModalResult property.

The VCL code in "Vcl.Forms.pas" on the other hand changes the TCustomForm.ModalResult value several times :
  • TCustomForm.Close
  • TCustomForm.CloseModal
  • TCustomForm.ShowModal
ChromiumWindow1Close is executed asynchronously and it can happen after the VCL code sets ModalResult to 0, which is equivalent to mrNone.
MiMi
Posts: 6
Joined: Tue Oct 12, 2021 10:30 am

Re: ModalResult value changes during closing process

Post by MiMi »

Thank you very much for your answer!
The source code in CEF4Delphi doesn't modify the ModalResult property.
ikr but maybe cef does...
Because if I remove the call to:

Code: Select all

ChromiumWindow1.CloseBrowser(True);
then ModalResult isn't changed
The VCL code in "Vcl.Forms.pas" on the other hand changes the TCustomForm.ModalResult value several times
Yes but "Vcl.Forms.pas" doesn't alter TCustomForm.ModalResult final value if it was set on purpose by the user

My problem is that I cannot use a Yes-No dialog and get the correct answer in a form that has Chromium browser with your recommended closing process
User avatar
salvadordf
Posts: 4580
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: ModalResult value changes during closing process

Post by salvadordf »

The browser destruction cancels the first form close to close the browser properly and then retries closing the form.

Perhaps the VCL code resets the ModalResult value after the first step.

Save the ModalResult value before cancelling the form closure.
MiMi
Posts: 6
Joined: Tue Oct 12, 2021 10:30 am

Re: ModalResult value changes during closing process

Post by MiMi »

Thanks!
Save the ModalResult value before cancelling the form closure.
This is what I've already done to fix it but I wanted to be sure that I wasn't missing something obvious...
Post Reply