Axapta Ax2012表单只能打开一次
大家好,我正在努力确保表单只打开一次。对于我的情况,我需要关闭旧表单并打开新表单。我尝试使用以下代码,但它会打开两个表单,请帮助我更正逻辑Axapta Ax2012表单只能打开一次,axapta,x++,dynamics-ax-2012,Axapta,X++,Dynamics Ax 2012,大家好,我正在努力确保表单只打开一次。对于我的情况,我需要关闭旧表单并打开新表单。我尝试使用以下代码,但它会打开两个表单,请帮助我更正逻辑 #define.CACHE_OWNER('CsPsqProdTableAttribConfig') #define.CACHE_KEY_INSTANCE('Instance') FormRun existingForm() { if (infolog.globalCache().isSet(#CACHE_OW
#define.CACHE_OWNER('CsPsqProdTableAttribConfig')
#define.CACHE_KEY_INSTANCE('Instance')
FormRun existingForm()
{
if (infolog.globalCache().isSet(#CACHE_OWNER, #CACHE_KEY_INSTANCE))
{
return infolog.globalCache().get(
#CACHE_OWNER, #CACHE_KEY_INSTANCE);
}
return null;
}
void registerThisForm()
{
infolog.globalCache().set(#CACHE_OWNER, #CACHE_KEY_INSTANCE, this);
}
boolean isAlreadyOpened()
{
return existingForm() ? !existingForm().closed() : false;
}
void closeExistingForm()
{
existingForm().close();
}
if (isAlreadyOpened())
{
closeExistingForm();
this.activate(true);
}
else
{
registerThisForm();
}
我猜您的问题是单例模式的客户机/服务器缓存 看看这里,看看如何引用缓存
SingletonTest singleton;
SysGlobalCache globalCache = infolog.objectOnServer() ? appl.globalCache() : infolog.globalCache();
;
if (globalCache.isSet(classStr(SingletonTest), 0))
singleton = globalCache.get(classStr(SingletonTest), 0);
else
{
singleton = new SingletonTest();
infoLog.globalCache().set(classStr(SingletonTest), 0, singleton);
appl.globalCache().set(classStr(SingletonTest), 0, singleton);
}
return singleton;
必须有一种更简单的方法来实现期望的行为。例如,您可以按如下方式修改表单的init。无需进行其他更改
public void init()
{
#define.CACHE_OWNER('CsPsqProdTableAttribConfig')
int hWnd;
super();
if (infolog.globalCache().isSet(#CACHE_OWNER, curUserId()))
{
hWnd = infolog.globalCache().get(#CACHE_OWNER, curUserId());
}
if (WinApi::isWindow(hWnd))
{
element.closeCancel();
WinAPI::bringWindowToTop(hWnd);
}
else
{
infolog.globalCache().set(#CACHE_OWNER, curUserId(), element.hWnd());
}
}