[英]Dynamics AX 2012 Only One Copy of a Form Open
任何人都有任何提示/代碼片段,以防止一次打開自定義X ++表單的多個副本?
最佳案例:嘗試打開表單的另一個副本,原始收益集中
可接受:用戶收到表單已打開的通知
您可以將下面的代碼插入到表單的init
方法中。 如果您對代碼有任何疑問,請不要猶豫!
public void init()
{
#define.CACHE_OWNER ('MyForm')
#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 activateExistingForm()
{
;
existingForm().activate(true);
}
;
super();
if (isAlreadyOpened())
{
activateExistingForm();
this.close();
}
else
{
registerThisForm();
}
}
將以下代碼添加到窗體的init
方法,如下所示。 無需其他更改。
public void init()
{
#define.CACHE_OWNER('MyForm')
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.