I’ve used the solutionModel in the past and haven’t had any problems, but for some reason this time around I’m having trouble removing my forms. When I click on a button, this code fires:
function loadMsgCenter(event)
{
//Set globals.g_WindowFlag
globals.g_WindowFlag = 0;
//show form in window
var md = application.createWindow('messageCenter',JSWindow.MODAL_DIALOG);
md.title = 'Message Center';
//Pass Window Name
globals.g_WindowName = md.getName();
forms.Message_Center3.controller.show(md);
}
The onShow of form Message_Center3 looks like this:
function onShow()
{
//Declare Variables
var success;
var form;
var groupQuery;
var groupDataset;
var show, close,newMsg;
var methShow, methClose, methNew;
var btnClose, btnNew;
var variable;
var btnBytes;
var btnImage;
var label;
//Remove forms
success = history.removeForm('Message_Buttons');
if(success)
{
solutionModel.removeForm('Message_Buttons');
}
//Set up new solutionModel form
form = solutionModel.newForm('Message_Buttons','eclinic','messages','eClinic',false,131,605);
form.borderType = "EmptyBorder, 0, 0, 0, 0";
form.navigator = SM_DEFAULTS.NONE;
//Create form variable nameHold
form.newFormVariable('nameHold',JSVariable.TEXT);
//Create Close Method
close = "function close(event){";
//call close window
close += " globals.Close_Window();";
close += " application.output(history.removeForm('Message_Buttons'));";
close += " application.output(solutionModel.removeForm('Message_Buttons'));";
//Set window flag
close += " globals.g_WindowFlag = 0;";
close += "}";
methClose = form.newFormMethod(close);
//Create buttons
btnBytes = plugins.file.readFile('C:/users/nicholas/servoy_workspace6/eclinic/medias/close.png');
btnImage = solutionModel.newMedia('close.jpg', btnBytes);
btnClose = form.newLabel('',5,194,121,45,methClose);
btnClose.imageMedia = btnImage;
btnClose.rolloverCursor = SM_CURSOR.HAND_CURSOR;
btnClose.borderType = "EmptyBorder, 0, 0, 0, 0";
btnClose.transparent = true;
btnClose.showClick = false;
btnClose.showFocus = false;
//set form in tab panel
elements.tabs_Msg_Buttons.addTab(forms['Message_Buttons'],null,null,null,null,null,null,null,null);
//Set tab visibility
elements.tab_inboxView.visible = false;
}
The global method Close_Window() that is called by clicking the close button is this:
function Close_Window()
{
//Declare Variables
var win;
//Set globals.g_WindowFlag
globals.g_WindowFlag = 1;
// close and dispose window resources
win = application.getWindow(globals.g_WindowName);
win.destroy();
win = application.getWindow(globals.g_WindowName);
if(win === null)
{
application.output("Window '" + globals.g_WindowName + "' has been destroyed");
globals.g_WindowName = null;
}
else
{
application.output("Window " + globals.g_WindowName + " could not be destroyed");
}
}
Also, the form Message_Center3 has an onHide method:
function ForminDialog_OnHide_Close()
{
// globals.g_WindowFlag = 1
if ( globals.g_WindowFlag != 1 )
{
application.output('ForminDialog_OnHide_Close returns false');
return false;
}
else
{
// globals.g_WindowFlag = null ;
application.output('ForminDialog_OnHide_Close returns true');
return true;
}
}
It works great the first time I click the button that sets everything in motion. After I close the form and hit the button again I get this error:
The name ‘Message_Buttons’ already exists as another form
Wrapped java.lang.RuntimeException: com.servoy.j2db.persistence.RepositoryException: The name ‘Message_Buttons’ already exists as another form
I also noticed when debugging that the function ForminDialog_OnHide_Close() executes, then immediately executes again. Don’t know if that has anything to do with my issue.
I assume this means I’m touching the solutionModel form ‘Message_Buttons’ in some way after the the win.destroy(), but I don’t see where. Can someone with a keen eye point out my mistake?
Thanks!