各位侠客:
    我在数据库中用一张表保存了程序里控件的名称与信息,想做一个权限管理功能,完成后怎么在软件启动时导入表中属性,数据表如下图我启动时的导入代码如下:
procedure TMainForm.LevelLoad;
var
  MMName:string;
  MMValues:Boolean;
  Comp:TComponent;
begin
  with qry1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select * from 权限管理 where 群组名称= '''+ LV +'''');
    Open;
  end;
  qry1.First;
  while not qry1.Eof do
  begin
  MMName:=qry1.fieldbyname('菜单名称').AsString;
  MMValues:=qry1.FieldByName('菜单值').AsBoolean;
  Comp.Name:=MMName;
  Comp.Enabled:=MMValues;//这里不对!
  qry1.Next;
  end;
end; 

解决方案 »

  1.   

    Comp:TComponent;
    这个地方应该TMENUM之类的吧
      

  2.   

    提示什么错误?你的Comp:TComponent 类的变量,还未实例化
      

  3.   

    Comp:TComponent;
    TComponent是没有Enabled属性的自己检查一下,具体是控件还是菜单
      

  4.   

      Comp.Name:=MMName;
      Comp.Enabled:=MMValues;//这里不对!
    之前没有对comp进行创建或指向
      

  5.   

    我现在改成这样了,但还是有点问题,请高手帮忙看看该如何写啊
    procedure TMainForm.LevelLoad;
    var
      MMName:string;
      MMValues:Boolean;
      Comp:TControl;
      cx:Integer;
    begin
      with qry1 do
      begin
        Close;
        SQL.Clear;
        SQL.Add('select * from 权限管理 where 群组名称= '''+ LV +'''');
        Open;
      end;  qry1.First;
      while not qry1.Eof do
      begin
      MMName:=qry1.fieldbyname('菜单名称').AsString;
      MMValues:= qry1.fieldbyname('菜单值').AsString;
        for cx:=0 to ComponentCount-1 do
        begin
          if  Components[i].Name=MMName then
          begin
             //想在这里实现该控件的 Enabled 属性=MMValues变量的值,该如何代码?      end;
        end;
      end;end;
      

  6.   

    终于弄明白了,下面的代码能实现,和大家分享一下:
    procedure TMainForm.LevelLoad;
    var
      MMName:string;
      MMValues:Boolean;
      Comp:TControl;
      cx:Integer;
    begin
      with qry1 do
      begin
        Close;
        SQL.Clear;
        SQL.Add('select * from 权限管理 where 群组名称= '''+ LV +'''');
        Open;
      end;  qry1.First;
      while not qry1.Eof do
      begin
      MMName:=qry1.fieldbyname('菜单名称').AsString;
      MMValues:= qry1.fieldbyname('菜单值').AsBoolean;
        for cx:=0 to ComponentCount-1 do
        begin      if  Components[cx].Name=MMName then
          begin
             
            if Components[cx] is TButton then
            begin
              (Components[cx] as TButton).Enabled:=MMValues;
            end;
            if Components[cx] is TMenuItem then
            begin
              (Components[cx] as TMenuItem).Enabled:=MMValues;
            end;
             if Components[cx] is TToolButton then
            begin
              (Components[cx] as TToolButton).Enabled:=MMValues;
            end;
            
          end;
        end;
        qry1.Next;
      end;
    end;
      

  7.   

    向阳:
        我来晚了呀~
    Components没有实例化
    建议用标识字段来做权限管控。