[英]Ax2012 form to be opened only once
嗨,我正在嘗試確保僅打開一次表單。對於我而言,我需要關閉舊表單並打開新表單。 我嘗試使用以下代碼,但同時打開了兩種形式,請幫助我糾正邏輯。
#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();
}
我猜您的問題是單例模式的客戶端/服務器緩存。
在此處查看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;
必須有一種更輕松的方式來實現所需的行為。 例如,您可以按以下方式修改表單的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());
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.