资讯   |   开发   |   选机中心   |   产品大全 | IBM | 惠普 | 联想 | 戴尔 | 苹果 | 神舟
更多: | 华硕 | 明基 | 方正 | 紫光 | TCL | 夏新 | 联宝 | 宏碁 | 七喜 | 长城 | 清华同方 | 海尔 | 三星 | 东芝 | 索尼 | 富士通 | LG | 技术 | ddnoon
当前位置:笔记本 > 软件开发 >
Advertisement
文章正文

用于权限设置的动态菜单,欢迎批评指正!!

类型:转载   责任编辑:asp.net   日期:2007/05/23


热门软件下载:


   

unit   main;  
   
  interface  
   
  uses  
      Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,  
      Dialogs,   Menus,   DB,   ADODB,   Grids,   DBGrids;  
   
  type  
      TForm1   =   class(TForm)  
          MainMenu1:   TMainMenu;  
          QueryMenuInf:   TADOQuery;  
          DataSource1:   TDataSource;  
          DBGrid1:   TDBGrid;  
          ADOConnection1:   TADOConnection;  
          QueryMenu:   TADOQuery;  
          DataSource2:   TDataSource;  
          DBGrid2:   TDBGrid;  
          procedure   FormCreate(Sender:   TObject);  
          procedure   FormClose(Sender:   TObject;   var   Action:   TCloseAction);  
      private  
          procedure   MenuItemCloseClick(Sender:   TObject);  
          procedure   MenuItemQuitClick(Sender:   TObject);  
          {   Private   declarations   }  
      public  
          {   Public   declarations   }  
      end;  
   
  var  
      Form1:   TForm1;  
  const  
      ConnectParam   =   Provider=Microsoft.Jet.OLEDB.4.0;+  
              Data   Source=%s\MenuInf.mdb;Persist   Security   Info=False;  
   
  implementation  
   
  {$R   *.dfm}  
   
  procedure   TForm1.FormCreate(Sender:   TObject);  
  var   i,j,iMenuNum1,iMenuNum2:   integer;  
          MenuArray1:   array   of   TMenuItem;  
          MenuArray2:   array   of   TMenuItem;  
          sMenuId:   string;  
  begin  
        ADOConnection1.ConnectionString:=Format(ConnectParam,  
                [ExtractFileDir(Application.ExeName)]);  
        ADOConnection1.LoginPrompt:=False;  
        ADOConnection1.Connected:=True;  
        with   QueryMenuInf   do  
        begin  
              Close;  
              SQL.Text:=select   *   from   menuinf   where   len(MenuId)=2+  
                      and   IsView=1;     //IsView:为1时显示;如果为0,则不显示,  
              Open;  
              iMenuNum1:=RecordCount;  
              First;  
        end;  
        if   iMenuNum1   >   0   then  
        begin  
              try  
              GetMem(MenuArray1,iMenuNum1*SizeOf(TMenuItem));  
              for   i:=1   to   iMenuNum1   do  
              begin  
                    MenuArray1[i-1]:=TMenuItem.Create(Self);  
                    MenuArray1[i-1].Caption:=  
                    QueryMenuInf.FieldByName(MenuName).AsString;  
                    MainMenu1.Items.Add(MenuArray1[i-1]);  
                    if   MenuArray1[i-1].Caption   =   退出   then  
                          MenuArray1[i-1].OnClick:=MenuItemCloseClick;  
                    sMenuId:=Trim(IntToStr(i));  
                    if   Length(sMenuId)   =   1   then   sMenuId:=0   +   sMenuId;  
                    with   QueryMenu   do  
                    begin  
                          Close;  
                          SQL.Text:=select   *   from   menuinf   where   len(MenuId)=4+  
                            and   left(MenuId,2)=+sMenuId+   and   IsView=1;  
                          Open;  
                          iMenuNum2:=RecordCount;  
                          First;  
                    end;  
                    if   iMenuNum2   >   0   then  
                    begin  
                          try  
                          GetMem(MenuArray2,iMenuNum2*SizeOf(TMenuItem));  
                          for   j:=1   to   iMenuNum2   do  
                          begin  
                                MenuArray2[j-1]:=TMenuItem.Create(Self);  
                                MenuArray2[j-1].Caption:=  
                                QueryMenu.FieldByName(MenuName).AsString;  
                                MenuArray1[i-1].Add(MenuArray2[j-1]);  
                                if   MenuArray2[j-1].Caption   =   退出   then  
                                      MenuArray2[j-1].OnClick:=MenuItemQuitClick;  
                                QueryMenu.Next;  
                          end;  
                          finally  
                                FreeMem(MenuArray2);  
                          end;  
                    end;  
                    QueryMenuInf.Next;  
              end;  
              finally  
                    FreeMem(MenuArray1);  
              end;  
        end;  
  end;  
   
  procedure   TForm1.MenuItemCloseClick(Sender:   TObject);  
  begin  
        Close;  
  end;  
   
  procedure   TForm1.MenuItemQuitClick(Sender:   TObject);  
  begin  
        Close;  
  end;  
   
  procedure   TForm1.FormClose(Sender:   TObject;   var   Action:   TCloseAction);  
  begin  
        if   MessageBox(Handle,您确认要退出程序吗?,提示,  
              Mb_OKCancel   +   Mb_IconQuestion)   =   1   then  
              Action:=caFree  
        else   Action:=caNone;  
  end;  
   
  end.  
 

网友回答:


 

 
热门推荐笔记本: 顶星笔记本
相关文章:
webmaster:popbb@126.com   最佳浏览:1024X768 MSIE
©2007 popbb.net All Rights Reserved