I have simply sorted out the menu processing process in the permission settings section previously written in the project. The idea is more general, but the code is not very common. Sorry, I am sorry for everyone. I will try again later!
(The tree in the program that gets all the objects of the system has been separated into an independent PBL: http://download.csdn.net/source/1551384)
Step 1: Save the menu to the database
// Function name wf_insert
// Function: Convert the input menu parameter into a data structure that forms a tree structure and store it to the database.
// Parameter List Value long superoid
// Value menu l_menu
// Value integer level
// Read all menus into the database in the first loop
Long I, ll_count
Long ll_oid
String ls_oname, ls_otext
Insert into sobjects (OID, oname, otext, otype, olevel, osort, superoid, Bz)
Values (0, 'menu _ main', 'main menu ', 1, 1, 1, null, null );
Ll_count = upperbound (l_menu.item)
For I = 1 to ll_count
Yield ()
Fig = superoid * 100 + I
Ls_oname = l_menu.item [I]. classname ()
Ls_otext = l_menu.item [I]. Text
Wf_set_stabar (ls_otext)
Insert into sobjects (OID, oname, otext, otype, olevel, osort, superoid, Bz)
Values (: ll_oid,: ls_oname,: ls_otext, 1,: Level,: I,: superoid, null );
If upperbound (l_menu.item [I]. Item)> 0 then
Wf_insert (ll_oid, l_menu.item [I], level + 1)
Else
Wf_insert_win (ll_oid, l_menu.item [I], level + 1)
End if
Next
Return 1
Step 2: Initialize the tree
// Configure //------------------------------------------------------------------------------------------
// 20070115 xuysh load several root nodes
//
// Configure //------------------------------------------------------------------------------------------
Str_objects lstr_new // node data variable
Treeviewitem ltvi_item // Node
This. deleteitem (0)
Lstr_new.oid = 0 // write dead, according to the ID maintained in the database
Lstr_new.olevel = 1 // write dead, the root is the first level
Lstr_new.osort = 1 // write dead, assign values according to the order
Lstr_new.otype = 1 // write dead, assign values according to different types, 1 = menu 2 = Window 3 = button 4 =... useless
Ltvi_item.label = "Main Menu"
Ltvi_item.data = lstr_new
Ltvi_item.pictureindex = 1
Ltvi_item.selectedpictureindex = ltvi_item.pictureindex
Ltvi_item.children = true
Il_root = This. insertitemlast (0, ltvi_item)
This. expanditem (il_root)
Step 3 write the code on the itempopulate event of the tree
// Configure //------------------------------------------------------------------------------------------
// 20070115 xuysh expand the node on the tree
//
// Configure //------------------------------------------------------------------------------------------
Integer I, li_rowcount
Str_objects lstr_new, lstr_this, lstr_parent
// String ls_thisdata, ls_pdata, ls_cdata
Treeviewitem ltvi_child, ltvi_parent, ltvi_this
Long ll_phandle, ll_chandle, ll_level
// Obtain the item of the current node
This. getitem (handle, ltvi_this)
Lstr_this = ltvi_this.data
// Obtain the parent node ite
Ll_phandle = This. finditem (parenttreeitem !, Handle)
If ll_phandle <>-1 then
This. getitem (ll_phandle, ltvi_parent)
Lstr_parent = ltvi_parent.data
End if
// Ll_level = ltvi_this.level
// Ids_objects.setfilter ("")
// Ids_objects.filter ()
// Filter out the leaf node item based on the ID stored in the item of the current node and load the expanded
Ids_objects.setfilter ("superoid =" + String (lstr_this.oid ))
Ids_objects.filter ()
Li_rowcount = ids_objects.rowcount ()
For I = 1 to li_rowcount
Lstr_new.oid = ids_objects.object.oid [I]
Lstr_new.superoid = ids_objects.object.superoid [I]
Lstr_new.olevel = ids_objects.object.olevel [I]
Lstr_new.oname = ids_objects.object.oname [I]
Lstr_new.osort = ids_objects.object.osort [I]
Lstr_new.otext = ids_objects.object.otext [I]
Lstr_new.otype = ids_objects.object.otype [I]
Ltvi_child.label = ids_objects.object.otext [I]
Ltvi_child.data = lstr_new
Ltvi_child.pictureindex = lstr_new.otype
Ltvi_child.selectedpictureindex = ltvi_child.pictureindex
Ltvi_child.children = true
This. insertitemlast (handle, ltvi_child)
Next
Ids_objects.setfilter ("")
Ids_objects.filter ()
Appendix 1
Global Type str_objects from Structure
Long OID
Long superoid
Long olevel
Long osort
String otext
String oname
Long otype
End type
Appendix 2
The tree on the left of the window is created according to the following data window. The data in the data window is generated by the specified menu.
Maintenance is provided on the right side of the window. After data is generated in the data window, you can refer to it and change the tree on the right.
The tree on the left and window can automatically correspond to one-to-one focus. For example, you can select a node on the tree to locate the corresponding row of datawindow, and vice versa.
Select the corresponding node in the tree on the right to display the corresponding code in the window below
Individual scrolling effects of each control:
Some of them are too long to be uploaded.