在delphi里,如何用0和1的字符串为系统分配权限,请给出代码

解决方案 »

  1.   

    这是一个算法问题,关键是理解,代码并不重要,而且要看你的程序是什么样的,权限要细化到什么程度。举个例子:简单的下拉菜单的程序,如果只需要控制到每个菜单的权限就很简单,把整个菜单的每个项映射到字串中的一位即可,  第m组菜单的第n项的权限可以用公式:((m-1)*MAXITEMS)+n,来取得,MAXITEMS是规定的每组菜单的最大值。  如第2组菜单的第4项可以公式 ((2-1)*MAXITEMS)+4,,如MAXITEMS =7,则此项菜单的权限可以在字串"101010111101010011..."中的第11位表示,如是'0'就没权限,是'1'就有权限。 这只是种思想,实际中,菜单可能不是这种简单的菜单,或者每个菜单还需控制到"进入,新建, 删除,修改"等等(我是用一个byte的8个位来实现几种操作的),就要变通了。
      

  2.   

    function tcgmain.power(uid,tname,done:string):boolean;
    //权限审核函数
    //uid用户id,tname表名,done操作
    //power1为权限字段char型10位,大部分只有1和0,1为有该权限,0无;
    //
    var
       s:string;
    begin
       with frm_yongkaidenglu.ADOQuery1 do
       begin
        close;sql.Clear;
        if (tname='采购系统') or  (tname='销售系统') or  (tname='仓库系统') then
        begin
         sql.Add('select power1 from power where userid='+''''+uid+'''');
        end
        else
        begin
         sql.Add('select power1 from power where userid='+''''+uid+''''+' and tablename='+''''+tname+'''');
        end;
        active:=true;
        s:=fieldbyname('power1').AsString;
       end;
       if       (done='采购子系统') and (strtoint(s[1])=1) then   begin   result:=true; end
       else if  (done='销售子系统') and (strtoint(s[2])=1) then   begin   result:=true; end
       else if  (done='仓库子系统') and (strtoint(s[3])=1) then   begin   result:=true; end
       else if  (done='采购审批')   and (strtoint(s[4])>0) then   begin   result:=true; end
       else if  (done='销售审批')   and (strtoint(s[5])>0) then   begin   result:=true; end
       else if  (done='系统') and (strtoint(s[6])=1)  then
       begin
        if       (tname='采购系统') and (strtoint(s[1])=1) then  result:=true
        else if  (tname='销售系统') and (strtoint(s[2])=1) then  result:=true
        else if  (tname='仓库系统') and (strtoint(s[3])=1) then  result:=true
        else     result:=false;
       end
       else if  (done='删除') and (strtoint(s[7])=1)  then   begin   result:=true; end
       else if  (done='修改') and (strtoint(s[8])=1)  then   begin   result:=true; end
       else if  (done='添加') and (strtoint(s[9])=1)  then   begin   result:=true; end
       else if  (done='查询') and (strtoint(s[10])=1) then   begin   result:=true; end
       else result:=false;
    end;
      

  3.   

    支持shao528(红雪) 代码不如思路重要
    可以用数据库存储功能组的可见菜单。
    每个人是属于某几个功能组。
    系统登录时调出其可见菜单,并由此生成用户主界面。
    一套系统,在用户看来成为如干个。功能可以自由搭配