唉,大富翁看来非要慢慢变成一个养懒人的地方了,一点脑子都不想动!
:-(
下面是检查权限的代码,原理大致为上所述,把每个用户的权限解密成AABABABABA
的形式,然后调用这个过程。我也给你的信箱发了一份。
Procedure TMainForm.CheckPower(power:string);
var FindMenu :integer;
begin
//权限检查
//方法:设定各个菜单的Tag属性不同,然后在PowerList库中
// 设定各项权限所能打开的Tag属性。检查权限的时候
// 就根据权限字符串来显示或隐藏菜单。
//1、先隐藏所有权限性菜单。
for FindMenu:=0 to MainForm.ComponentCount-1 do
begin
if MainForm.Components[FindMenu] is TMenuItem then
begin
if (MainForm.Components[FindMenu] as TMenuItem).Tag <>0 then
//等于0的是公共菜单,如退出程序,关于程序之类的。
(MainForm.Components[FindMenu] as TMenuItem).Visible := false;
end;
end;
//2、开始检查权限
try
with MainDataModule.UserSecADOQuery do
begin
Close;
SQL.Clear;
SQL.Add('select * from powerlist');
Open;
while not Eof do
begin
if Copy(power,RecNO,1)='A' then
begin
if FieldByName('权限能力').AsInteger >0 then
begin
for FindMenu:=0 to MainForm.ComponentCount-1 do
begin
if MainForm.Components[FindMenu] is TMenuItem then
begin
if (MainForm.Components[FindMenu] as TMenuItem).Tag = FieldByName('权限能力一').AsInteger then
(MainForm.Components[FindMenu] as TMenuItem).Visible := true;
end;
end;
end;
end;
Next;
end;
end;
except
Application.MessageBox('调用权限表时出错,只能使用默认权限,请与系统管理员联系!',
'权限调用失败!',MB_OK);
end;
end;