Tutorials to .com

Tutorials to .com » Software » Power-builder » How to dynamically add the use of PB menu (original)

How to dynamically add the use of PB menu (original)

Print View , by: iSee ,Total views: 33 ,Word Count: 6286 ,Date: Sun, 19 Apr 2009 Time: 4:07 PM

Author: BALLOONMAN2002   June 26, 2004

POWERBUILDER language in connection with this article, outlining how to achieve the effect of dynamic add menu. The actual development process in many cases because of the need for access control, according to the different user permissions to dynamically add menu items, how to avoid the use of cumbersome API functions (such as: CreateMenu, InsertMenu, InsertMenuItem, AppendMenu etc.), use their own language function POWERBUILDER achieve this purpose? In this paper, this issue will be discussed briefly.

First, the basic idea

PB help in a MENU OBJECT who were on their description of a PROPERTIES:

Item [] Menu     Specifies the Menu objects under a Menu object.

This remark seems to be simple and in fact contains three meanings:

1, this object that there is a MENU for array type attributes, the various elements of which it recorded all of its sub-ITEM specific projects, can make use of this array to access the underlying elements of the sub-menu;

2, which is still sub-ITEM item MENU type, therefore the first point in accordance with the logic to continue to lower promotion, with the sub-ITEM in ITEM [] attributes can then visit their respective sub-classes of second-tier menu, by extension, can traverse the entire menu system full of all the sub-menu items;

3, since the attribute is an array type, it can be in accordance with the array type variable to deal with, we can carry out its upperbound (), lowerbound () function, such as the operation can also be used for the expansion of the array, that is to add a new item, this very important, it is the core of our article was, how to use PB to add dynamic menu, that white is added to this array of elements (the reader must have a clear understanding of), at the same time period a number of supporting the achievement of specific skills, in detail see below.

Second, the specific realization of

(A) the basic work

WINDOW to create a window and two MENU menu, one menu named m_main, used as the basic main menu window, a new menu will be added in its, the menu can include some of the basic initial menu, such as: documents, add, delete, save, exit, etc.; a menu named m_new, the menu is only one main menu ITEM, under no further sub-menu, so the menu is actually a menu ITEM.

Statement in the main window instance variables (INSTANCE VARIABLES):

menu im_new [] / / declaration of a menu used to invoke an array of new menu

integer ii_count / / declaration of a variable number of records total Add menu

(B) of the specific code

1, to add a menu function to achieve:

//////////////////////////////////////////////

/ /

/ / Purpose: In the last, as well as a new menu after a menu

/ / Time :2003-6-1

/ /

//////////////////////////////////////////////

integer li_itemcount   / / The statement variable records the total number of the current menu level;

/ / Create a new menu object, and on the menu array im_new [] them;

ii_count + +

im_new [ii_count] = create m_new

/ / Here on the newly created menu object to obtain reference;

li_itemcount = upperbound (m_main.item [])

m_main.item [li_itemcount + 1] = im_new [ii_count]. item [1]

/ / The following is a new generation of the TEXT menu attributes, this attribute can be taken from the database, but omitted here to simplify the lost;

m_main.item [li_itemcount + 1]. text = "new level -" + string (li_itemcount + 1)

/ / The following is the menu set up a new generation of TAG attribute, this attribute can be taken from the database, but omitted here to simplify the lost;

/ / Through the TAG can be used as a function of its use, etc., through gf_menumessage () function to be public to deal with;

/ / m_main.item [li_itemcount + 1]. tag = "xxxxxxxxx"

/ / Here come the new menu generated objects displayed;

m_main.item [1]. hide ()

m_main.item [1]. show ()

2, add two menu functions to achieve:

//////////////////////////////////////////////

/ /

/ / Use: a menu in the last two under a new menu

/ / Time :2003-6-1

/ /

//////////////////////////////////////////////

/ / The statement variable records the total number of the current menu level, and finally a two-level menu, the corresponding total number of menu;

integer li_precount, li_itemcount

/ / Create a new menu object, and on the menu array im_new [] them;

ii_count + +

im_new [ii_count] = create m_new

/ / Here on the newly created menu object to obtain reference;

li_precount = upperbound (m_main.item [])

li_itemcount = upperbound (m_main.item [li_precount]. item [])

m_main.item [li_precount]. item [li_itemcount + 1] = im_new [ii_count]. item [1]

/ / The following is a new generation of the TEXT menu attributes, this attribute can be taken from the database, but omitted here to simplify the lost;

m_main.item [li_precount]. item [li_itemcount + 1]. text = "Added 2 -" + string (li_precount) + "-" + string (li_itemcount + 1)

/ / The following is the menu set up a new generation of TAG attribute, this attribute can be taken from the database, but omitted here to simplify the lost;

/ / Through the TAG can be used as a function of its use, etc., through gf_menumessage () function to be public to deal with;

/ / m_main.item [li_precount]. item [li_itemcount + 1]. tag = "xxxxxxxxx"

/ / Here come the new menu generated objects displayed;

m_main.item [1]. hide ()

m_main.item [1]. show ()

3, to add functions to achieve the three-tier menu:

//////////////////////////////////////////////

/ /

/ / Purpose: In the last two under a new three-tier menu Menu

/ / Time :2003-6-1

/ /

//////////////////////////////////////////////

/ / The statement variable records the total number of the current menu level, and finally a two-level menu, the corresponding total number of menu;

integer li_fircount, li_precount, li_itemcount

/ / Create a new menu object, and on the menu array im_new [] them;

ii_count + +

im_new [ii_count] = create m_new

/ / Here on the newly created menu object to obtain reference;

li_fircount = upperbound (m_main.item [])

li_precount = upperbound (m_main.item [li_fircount]. item [])

if li_precount = 0 then

    messagebox ( "prompt", "please click on - to add two menu - button to create a secondary menu ,:)")

    return

end if

li_itemcount = upperbound (m_main.item [li_fircount]. item [li_precount]. item [])

m_main.item [li_fircount]. item [li_precount]. item [li_itemcount + 1] = im_new [ii_count]. item [1]

/ / The following is a new generation of the TEXT menu attributes, this attribute can be taken from the database, but omitted here to simplify the lost;

m_main.item [li_fircount]. item [li_precount]. item [li_itemcount + 1]. text = "new three-tier -" + string (li_fircount) &

                                              + "-" + String (li_precount) + "-" + string (li_itemcount + 1)

/ / The following is the menu set up a new generation of TAG attribute, this attribute can be taken from the database, but omitted here to simplify the lost;

/ / Through the TAG can be used as a function of its use, etc., through gf_menumessage () function to be public to deal with;

/ / m_main.item [li_precount]. item [li_itemcount + 1]. tag = "xxxxxxxxx"

/ / Here come the new menu generated objects displayed;

m_main.item [1]. hide ()

m_main.item [1]. show ()

4, dealing with dynamically generated menu CLICKED event:

The overall idea is the use of the parameters of thought, with a unified function, in accordance with different parameters to be functions of different treatments.

(1) dealing with m_new object clicked event:

////////////////////////////////////////////////// //////////////////////

/ /

/ / Use: According to the new generation of the menu number corresponding to the function, that is, removed from the database of the TAG property

/ /       To call gf_menumessage () global function to achieve different system functions;

/ / Time :2003-6-1

/ /

////////////////////////////////////////////////// //////////////////////

/ / Here should be to call the gf_menumessage () global function to deal with different functions to handle the functions of the corresponding number,

/ / But here are a little lost, can be found in the specific content of gf_menumessage () function;

/ / Here only demonstrate a messagebox () function, as follows;

/ / integer li_ret

/ / li_ret = gf_menumessage (this.tag)

/ / The following code is to avoid clicking the next level sub-menu contains menu will pop-up dialog box, resulting in a menu can not be displayed under the circumstances;

if upperbound (this.item [])> 0 then

    return

end if

messagebox ( "dynamic menu presentation", "click on your current menu is:" + this.text)

(2) the preparation of gf_menumessage function:

////////////////////////////////////////////////// //////////////////////

/ /

/ / Use: According to the new menu generated by the corresponding function into its mass, that is, removed from the database of the TAG property

/ /       To dynamically determine the operation to be carried out;

/ / Time :2003-6-1

/ / Input: string type as_funcode: Chuan-enter the corresponding menu number in order to achieve the functions;

/ / Output: integer type   1: success

/ /                 -1: Failed

/ /

////////////////////////////////////////////////// //////////////////////

/ / Note: According to the new menu generated by the corresponding function into its mass, that is, removed from the database of the TAG property

/ /     To dynamically determine the operation to be carried out; this need to connect the database, the ideas outlined here, specifically a little

string ls_funcode / / declaration of a variable used to record into the function of its mass;

ls_funcode = as_funcode

choose case ls_funcode

    case "1"

        For example, a representative of //...... storage management, storage management functions to call gf_rk (), etc.

    case "2"

        For example, 1 //...... management on behalf of the Treasury, then to call out the Treasury Management function gf_ck (), etc.

    //......

   case else

        return -1

end choose

return 1

At this point, the effect of dynamic add complete menu, see View:

http://blog.csdn.net/images/blog_csdn_net/balloonman2002/17312/r_ADD_MENU.JPG

For further information, please contact QQ: 27855043, MSN: WEIYIN2001@MSN.COM

If inappropriate, I hope you respect the point.


Power Builder Tutorial Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.