2014-11-25 93 views
0

您好,我试图确保窗体只打开一次。对于我需要关闭旧窗体并打开新窗体的情况。我尝试使用下面的代码,但它打开这两种形式,请帮我纠正逻辑。Ax2012窗体只能打开一次

#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(); 
    } 

回答

0

我猜测,你的问题是客户端/服务器缓存与Singleton模式。

看这里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; 
0

必须有一种更简单的方法来实现所需的行为。例如。您可以修改表格的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()); 
    } 
}