有一表存放的是菜单的名称
例如:
表A
code    MenuName           
01      MenuMain_open
02      MenuMain_close
菜单的enabled都等于false
现在我要将enabled都等于true
则:
    while not a.eof do
          begin
            a.FieldByName('MenuName').AsString.enabled:=true;
            //这句显然是不行的
          end;
请问:有没有什么办法实现这个功能,谢谢

解决方案 »

  1.   

    VAR
      I:INTEGER;
    begin
       FOR I:=0 TO SELF.MainMenu1.Items.Count-1 DO
       BEGIN
         SELF.MainMenu1.Items[I].Enabled:=TRUE;
       END;
    end;
      

  2.   

    to tiexinliu(铁心刘) 
      对不起,我写的有些不清楚:
          有一表存放的是菜单的名称
    例如:
    表A
    code    MenuName           Menuqx
    01      MenuMain_open      1
    02      MenuMain_close     0
    菜单的enabled都等于false
    现在我要将enabled按条件等于true
    则:
        while not a.eof do
              begin
                 if a.FieldByName('Menuqx').AsString='1') then 
                    a.FieldByName('MenuName').AsString.enabled:=true;
                    //这句显然是不行的
              end;
    请问:有没有什么办法实现这个功能,谢谢
      

  3.   

    你应该先根据菜单判断,如果菜单的Name等于你的数据库的内容,然后再设置菜单的enabled的属性。
      

  4.   

    你想用Menuqx来标志菜单是否可用,可是delphi认为false是-1,true 是0,你最好保存-1和0,然后
    使code和menu的顺序一致,这样用menu.items[i].enabled:=a.FieldByName('Menuqx').asboolean;更高效一点,不然你要根据menu的itemname遍历数据库,效率不高.
      

  5.   

    while not a.eof do
              begin
                 if a.FieldByName('Menuqx').AsString='1') then 
                    TMenuItem(self.FindComponent(a.FieldByName('MenuName').AsString)).enabled:=true;
                    //这样就行了
              end;
      

  6.   

    adoquery1.sql.add('update A set Menuqx=1');
    执行不就行了吗?
      

  7.   

    yoic做法是对的。
    给分吧。
      

  8.   

    to tiexinliu(铁心刘) 
       我知道你的意思,menu.items[i]跟a.FieldByName('Menuqx')的顺序必须一致
    这个条件我满足不了
    to yoic(我是一棵菠菜,菜,菜,菜,菜,菜,菜)
       你的代码我试了,过不去
    to mingjunlee(包身工)
       谢谢你的支持解决后我给大家散分
      

  9.   

    VAR
      I:INTEGER;begin
     while not a.eof do
              begin
                 if a.FieldByName('Menuqx').AsString='1') then 
                      FOR I:=0 TO SELF.MainMenu1.Items.Count-1 DO
                              BEGIN
                                  if MainMenu1.Items[I].name=a.FieldByName('Menuname').value then
                                  SELF.MainMenu1.Items[I].Enabled:=TRUE;
     
                              END;
                end;
    end;
      

  10.   

    我拭目以待,不过不太懂!
    我学DELPHI的第五天!
      

  11.   

    修改一下:
    VAR
      I:INTEGER;begin
     while not a.eof do
              begin
                 if a.FieldByName('Menuqx').AsString='1') then 
                      FOR I:=0 TO SELF.MainMenu1.Items.Count-1 DO
                              BEGIN
                                  if MainMenu1.Items[I].caption=a.FieldByName('Menuname').value then
                                  SELF.MainMenu1.Items[I].Enabled:=TRUE;
     
                              END;
                 a.next
                end;
    end;
      

  12.   

    wguoq (明月剑) 是不是每条记录的Menuqx值都相同的啊?
    如果不同应该这样的:
    VAR
      I:INTEGER;begin
     while not a.eof do
        begin
           FOR I:=0 TO SELF.MainMenu1.Items.Count-1 DO
           BEGIN                
           if a.FieldByName('Menuqx').AsString='1') then 
              if MainMenu1.Items[I].caption=a.FieldByName('Menuname').value then
              SELF.MainMenu1.Items[I].Enabled:=TRUE;
           end;
         a.next
       end;
    end;
      

  13.   

    楼主:报什么错误?
          (你有没有引用menus单元?)
      

  14.   

    a.FieldByName('MenuName').AsString这是什么意思
    这只是字符串,不是对象当然不行了,你应该动态添加菜单
      

  15.   

    wguoq(明月剑) 可以说一下你那里错了,可以大家一起学习