Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Wed Nov 14, 2018 7:45 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: what is the best way to make a 'save before closing' dialog?
PostPosted: Wed Aug 22, 2012 2:12 pm 
Offline

Joined: Fri Dec 09, 2005 6:25 pm
Posts: 357
I want to add a dialog box that warns the user to save when they close the main window of the app. what is the best way to do this? I want a Cancel, Don't Save, and Save button and obviously if they cancel the window just stays open.


Top
 Profile  
Reply with quote  
 Post subject: Re: what is the best way to make a 'save before closing' dia
PostPosted: Wed Aug 22, 2012 2:33 pm 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
use the MessageDialog (expanded version of MsgBox).. you can customize it any way you want (almost)

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: what is the best way to make a 'save before closing' dia
PostPosted: Wed Aug 22, 2012 4:04 pm 
Offline

Joined: Fri Dec 09, 2005 6:25 pm
Posts: 357
Not sure what I'm doing wrong. I have this code in the main window's Close event handler and I want it to keep the window open, but if you click Cancel, the window still closes, then the app crashes shortly after that.

Dim md as New MessageDialog //declare the MessageDialog object
Dim b as MessageDialogButton //for handling the result
md.icon=MessageDialog.GraphicCaution //display warning icon
md.ActionButton.Caption="Save"
md.CancelButton.Visible= True //show the Cancel button
md.AlternateActionButton.Visible= True //show the "Don't Save" button
md.AlternateActionButton.Caption="Don't Save"
md.Message="Do you want to save changes to this project before closing?"
md.Explanation="If you don't save, your changes may be lost. "


if listBox1.listCount > 0 or MoviePlayer1.movie <> nil then
b=md.ShowModal //display the dialog
Select Case b //determine which button was pressed.
Case md.ActionButton
//user pressed Save
if app.savedFilePath <> "" then
save
else
saveas
end if
Case md.AlternateActionButton
//user pressed Don't Save
close
Case md.CancelButton
//user pressed Cancel
return
End select
end if


Top
 Profile  
Reply with quote  
 Post subject: Re: what is the best way to make a 'save before closing' dia
PostPosted: Wed Aug 22, 2012 4:07 pm 
Offline

Joined: Wed May 20, 2009 4:43 pm
Posts: 958
pbesong wrote:
Not sure what I'm doing wrong. I have this code in the main window's Close event handler and I want it to keep the window open, but if you click Cancel, the window still closes, then the app crashes shortly after that.

Dim md as New MessageDialog //declare the MessageDialog object
Dim b as MessageDialogButton //for handling the result
md.icon=MessageDialog.GraphicCaution //display warning icon
md.ActionButton.Caption="Save"
md.CancelButton.Visible= True //show the Cancel button
md.AlternateActionButton.Visible= True //show the "Don't Save" button
md.AlternateActionButton.Caption="Don't Save"
md.Message="Do you want to save changes to this project before closing?"
md.Explanation="If you don't save, your changes may be lost. "


if listBox1.listCount > 0 or MoviePlayer1.movie <> nil then
b=md.ShowModal //display the dialog
Select Case b //determine which button was pressed.
Case md.ActionButton
//user pressed Save
if app.savedFilePath <> "" then
save
else
saveas
end if
Case md.AlternateActionButton
//user pressed Don't Save
close
Case md.CancelButton
//user pressed Cancel
return
End select
end if

When the Close event occurs, the window is closing. Put your code in the 'CancelClose' event, and return true when you want to keep the window open.

_________________
RB 2009r4 Windows XP


Top
 Profile  
Reply with quote  
 Post subject: Re: what is the best way to make a 'save before closing' dia
PostPosted: Wed Aug 22, 2012 4:19 pm 
Offline

Joined: Fri Dec 09, 2005 6:25 pm
Posts: 357
oh ok. i'll give that a shot. thanks!


Top
 Profile  
Reply with quote  
 Post subject: Re: what is the best way to make a 'save before closing' dia
PostPosted: Wed Aug 22, 2012 5:48 pm 
Offline

Joined: Fri Dec 09, 2005 6:25 pm
Posts: 357
worked like a charm. i never even noticed the cancelclose event. thanks again.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group