[英]Ax2012 form to be opened only once
HI all I am trying to make sure the form is opened only once.For my case where i need to close the old form and open the new form. 嗨,我正在尝试确保仅打开一次表单。对于我而言,我需要关闭旧表单并打开新表单。 i tried using the following code but it opens the both forms, please help me in correcting the logic. 我尝试使用以下代码,但同时打开了两种形式,请帮助我纠正逻辑。
#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();
}
I'm guessing that your problem is client/server cache with your singleton pattern. 我猜您的问题是单例模式的客户端/服务器缓存。
Look here http://www.axaptapedia.com/Singleton_pattern to see how you can reference the caches. 在此处查看http://www.axaptapedia.com/Singleton_pattern,以了解如何引用缓存。
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;
There must be an easier way of achieving desired behaviour. 必须有一种更轻松的方式来实现所需的行为。 Eg you can modify the init
of the form as follows. 例如,您可以按以下方式修改表单的init
。 No other changes are required. 无需其他更改。
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());
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.