jahlxx Posted March 29, 2019 Share Posted March 29, 2019 Hi. I need to prevent data lose when a user close the browser or the tab where de unigui app is running. I'm trying some options. One of them is in MainModule, the event OnBrowserClose. Tee event is detected, but don`t executes my code. Any idea and / or help? Thanks Quote Link to comment Share on other sites More sharing options...
jahlxx Posted April 3, 2019 Author Share Posted April 3, 2019 Hi. Is there any way to control this? Thanks. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 3, 2019 Share Posted April 3, 2019 On 3/30/2019 at 1:01 AM, jahlxx said: Tee event is detected, but don`t executes my code. Hi, What code is not executed, can you clarify? Quote Link to comment Share on other sites More sharing options...
jahlxx Posted April 3, 2019 Author Share Posted April 3, 2019 Well. procedure TUniMainModule.UniGUIMainModuleBrowserClose(Sender: TObject); begin if formdata.haycambios then //MessageDlg('Hello); MessageDlg('There are changes Do you want to update them ?', system.uitypes.TMsgDlgType.mtconfirmation, [system.uitypes.TMsgDlgBtn.mbYes, system.uitypes.TMsgDlgBtn.mbNo, system.uitypes.TMsgDlgBtn.mbCancel], formdata.update_data); end; Don't raises the dialog, and don`t executes the formdada.update_dada procedure Thanks Quote Link to comment Share on other sites More sharing options...
neo4a Posted April 4, 2019 Share Posted April 4, 2019 UniGUIMainModuleBrowserClose() is called right after browser or tab is already closed. Not before. Quote Link to comment Share on other sites More sharing options...
jahlxx Posted April 4, 2019 Author Share Posted April 4, 2019 Ok. Then, how can I do what I need to do? Thanks. Quote Link to comment Share on other sites More sharing options...
neo4a Posted April 4, 2019 Share Posted April 4, 2019 Unless you havn't full control over the browser app window, there is no reliable method. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 4, 2019 Share Posted April 4, 2019 7 minutes ago, jahlxx said: Then, how can I do what I need to do? Hi, Immediately run the code or warn the user: UniMainModule -> BackButtonAction = bbaWarnUser Quote Link to comment Share on other sites More sharing options...
jahlxx Posted April 4, 2019 Author Share Posted April 4, 2019 Ok. THis wran the user. But how can I execute my code? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 4, 2019 Share Posted April 4, 2019 2 hours ago, jahlxx said: But how can I execute my code? Sorry, how or where? You can use the MainModule -> OnDestroy event for this I think (without MessageDialogs of course) Quote Link to comment Share on other sites More sharing options...
jahlxx Posted April 5, 2019 Author Share Posted April 5, 2019 Ok. Can I change UniMainModule.BackButtonAction in runtime? I could set by default to bbaDoNothing, and set to bbWarnUser if the user has done some changes . If yes, how? And how can I change the default message? With this, I almost have what I need. Thanks. Quote Link to comment Share on other sites More sharing options...
jahlxx Posted April 5, 2019 Author Share Posted April 5, 2019 Hi. Answer myself. Yes, I can change UniMainModule.BackButtonAction in run time. But, how can I change the message text? Thanks Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 5, 2019 Share Posted April 5, 2019 14 minutes ago, jahlxx said: But, how can I change the message text? https://www.w3schools.com/jsref/event_onbeforeunload.asp Quote Link to comment Share on other sites More sharing options...
jahlxx Posted April 5, 2019 Author Share Posted April 5, 2019 Sorry, I need more details. What object must I use? Any sample please? I only want to change the message text. Thanks. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 5, 2019 Share Posted April 5, 2019 24 minutes ago, jahlxx said: I only want to change the message text. The default message that appears in the confirmation box, is different in different browsers. However, the standard message is something like "Are you sure you want to leave this page?". This message cannot be removed. However, you can write a custom message together with the default message. See the first example on this page. Note: This only works in Internet Explorer. https://www.w3schools.com/jsref/event_onbeforeunload.asp Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 5, 2019 Share Posted April 5, 2019 ... Quote Link to comment Share on other sites More sharing options...
jahlxx Posted April 5, 2019 Author Share Posted April 5, 2019 Ok. Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.