In Delphi Tips Management Management When using Delphi to prepare some application systems, there are many times to give different privileges to different users, and different systems have different authority allocations, if they go in the program If the user allocates permissions, not only makes the program is very troublesome, and it is not conducive to management! The author recently thought of a better way to think, would like to share with everyone, and hope that you will advise!
In many systems, permissions are usually divided into several levels. The operations that users can implement each level are different, and the method of implementing this feature is generally a different menu for users with different permissions. Simply put is that the menu for users who do not have a permission is not visible! In order to achieve this control, the programmers often take a lot of time to do this module, wasting a lot of valuable time!
The idea of the author is: If you set a two-dimensional array, the first dimension represents the first level menu, the second dimension representative submenu, each array element is only stored by 0 or 1, and the user of a certain permission corresponds to one. Two-dimensional arrays, and this array represents the corresponding menu. After a certain level of users allocated permissions, he has a corresponding array. When logging in, remove the values of each element from the array. If it is 1, the corresponding menu appears, does not appear in the menu. In this way, it can not only be graded (the same as the number of users of the same order), but also implement the permission segment between different users, as long as you modify the corresponding value of 0 or 1!
The above is a simple example of running results. Below is a partial program (this is just an interpretative example program), in order to easily, there is only one form and a main menu in the program. Initialize the array m when the form is created, the array value is read, and the display is controlled by setting the enabled attribute of the setting menu or the true or false of the Visible property. ! Var Form1: TForm1; M: Array [0..1, 0..4] of integer; // Define the stored array I, J: Integer; // Defines the variable of the loop
IMPLEMENTATION
{$ R * .dfm}
Procedure TForm1.FormShow (Sender: TOBJECT); Begin // Reads Digital and Controls Display for i: = Low (M) to High (M) Do for J: = Low (M [i]) To Highh (M [i]) Do Begin IF M [I] [J] = 0 Then MainMenu1.items [i] .Items [J] .Enable: = false else mainmenu1.items [i] .Items [J] .enable: = true ; End;
Procedure TForm1.FormCreate (Sender: TOBJECT); Begin // below is initialization K: = 0; for i: = low (m) to high (m) do for j: = low (M [i]) to high (M [i]) DO if (j mod 2) = 0 THEN M [I] [J]: = 1 else m [i] [j]: = 0;
In actual applications, users' permissions arrays are generally recorded in the user's information record table. Remove this array when logging in, it is possible to look similar to the above steps. Of course, readers can define three-dimensional four-dimensional or even more dimensions according to their needs. Since I first involved Delphi, please include you! Welcome to communicate with me: lixin9826@sina.com.
Wuhan University Physics Institute 2001 Electronic Technology One Class Li Xin 2003-4-14