各位侠客:
我在数据库中用一张表保存了程序里控件的名称与信息,想做一个权限管理功能,完成后怎么在软件启动时导入表中属性,数据表如下图我启动时的导入代码如下:
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;
我在数据库中用一张表保存了程序里控件的名称与信息,想做一个权限管理功能,完成后怎么在软件启动时导入表中属性,数据表如下图我启动时的导入代码如下:
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;
这个地方应该TMENUM之类的吧
TComponent是没有Enabled属性的自己检查一下,具体是控件还是菜单
Comp.Enabled:=MMValues;//这里不对!
之前没有对comp进行创建或指向
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;
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;
我来晚了呀~
Components没有实例化
建议用标识字段来做权限管控。