函數glDefinePopup(),動態定義多級的popup菜單

來源:互聯網
上載者:User

動態定義POPUP,涉及字串處理、遞迴、菜單定義語句等等。

也挺費勁的,。

做出這個函數,就可擴充基類 _FORM, 以加上 介面:_c菜單定義 、_v菜單事件() 。  

(1) 使用例子

TEXT to cMenu 
檔案
    開啟
        EXCEL
        WORD
    關閉
    Quit
    
編輯
    Copy
    paste
協助    
ENDTEXT

glDefinePopup(cMenu,'abc')    
Activate Popup abc

(2)函數定義

*******************************************************************
Function glDefinePopup()Function glDefinePopup
Lparameters tcPopupDefine, tcPopupName 
*- 功能: 定義多級的關聯popup菜單
*-
*- 參數
*- (1) tcPopupDefine: 菜單定義字串,每項以換行分隔,以TAB確定層級
*- 例子: 
*- text to cPpDefine
*-    檔案
*-        開啟
*-            EXCEL
*-            WORD
*-        關閉
*- endtext
*-
*- (2) tcPopupName: 定出來的POPUP的名字
*-
Local i,cLine,n當前級數,n上級id_

Release POPUPS (tcPopupName) extended 

*- 轉變為鏈表結構 ----------------
Create Cursor _csDefine_menu_MenuStru (id_ i , fid_ i , 菜單定義 c(240), 級數 i,子女數 i )
For i=1 to GetWordCount(tcPopupDefine,Chr(13))
    cLine = Alltrim( GetWordNum(tcPopupDefine,i,Chr(13)) , 1, Chr(10),Chr(32))
    If Empty(cLine)
        Loop
    EndIf 
    n當前級數 =  _n求級數(cLine) 

    n上級id_=0
    Do while not bof() && 往回找,找到層級比自己小[1級]的, 就是父. 取其id作fid_, 父的子女數+1
        If 級數 < n當前級數
            n上級id_ =  id_
            Replace 子女數 with 子女數+1
            Exit
        EndIf         
        Skip -1
    EndDo 
    
    Append Blank 
    Replace id_ with i, fid_ with n上級id_, 級數 with n當前級數, 菜單定義 with Ltrim(cLine,1,Chr(9)) 
Next 

_vDefinePopUp(0,0,tcPopupName)
Return .t.
**********************************************
Function _vDefinePopup()Function _vDefinePopup
Lparameters tn上級id, tn上級barID, tc上級popUp名
Local nBarCnt,nRecNo,c本級popup名

    
If tn上級barID = 0
    c本級popup名 = tc上級popUp名
Else
    c本級popup名 = tc上級popUp名+'_'+Alltrim(Str(tn上級barID,10))
    _vfp.DoCmd( Textmerge('On Bar <<tn上級barID>> of <<tc上級popUp名>> activate popup <<c本級popup名>>'))
EndIf     
_vfp.DoCmd( Textmerge("Define Popup <<c本級popup名>> shortcut relative "))
_vfp.DoCmd( Textmerge("On Selection Popup <<c本級popup名>> Deactivate Popup <<c本級popup名>> "))
*---

nBarCnt=0
nRecNo=Recno()
Scan for fid_ = tn上級id
    nBarCnt = nBarCnt + 1 
    _vfp.DoCmd( Textmerge("define Bar <<nBarCnt>>  of <<c本級popup名>> prompt '<<Trim(菜單定義)>>' " ))
    
    If 子女數 > 0
        _vDefinePopup(id_,nBarCnt,c本級popup名)
    EndIf     
EndScan 
Go (nRecNo)
Return 

**********************************************
Function _n求級數()Function _n求級數
Lparameters tcStr
Local nCnt,i
nCnt=0
For i=1 To Len(tcStr)
    If Substr(tcStr,i,1)=Chr(9)
        nCnt = nCnt + 1
    Else
        Exit
    Endif
Next

Return nCnt+1
**********************************************************


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.