大虾,我的问题很简单,帮我看一下,就差这一步就可以交作业了.关于Ttreeview如何根据用户的权限显式或隐藏? ( 积分: 40 )

  • 主题发起人 主题发起人 ff_ff
  • 开始时间 开始时间
F

ff_ff

Unregistered / Unconfirmed
GUEST, unregistred user!
一个小系统,用Ttreeview把菜单的各项都显示出来了.
可是菜单是根据不同用户的权限来显示,但Ttreeview如何才能实现?


qx:array [1..4] of boolean;分配四种不同的权限.
var
MainForm: TMainForm;
username:string;
qx:array [1..4] of boolean;
i:Integer;
implementation
uses uLogin, uBooiIn,uOperator,BookBrower,units, PasswordChange,classmanage,bookfee,
returnfee;

{$R *.dfm}

procedure TMainForm.FormActivate(Sender: TObject);
//var
// i:Integer;
begin
frmLogin.ShowModal;
if Right=False then
begin
for i:=0 to 3 do
begin
// if (i<>4) and (Right=False) then
frmLogin.ShowModal;
if Right=True then Break;
end
end;

if username<>'' then
begin
if qx[1] then[red]这里是菜单的权限分配[/red]
begin
N2.Enabled:=true;
N3.Enabled:=true;
N4.Enabled:=true;
N6.Enabled:=true;
N7.Enabled:=true;
N9.Enabled:=true;

end else
begin
N2.Enabled:=false;
N3.Enabled:=false;
N4.Enabled:=false;
N6.Enabled:=false;
N7.Enabled:=false;
N9.Enabled:=false;

end;
if qx[2] then
begin
N15.Enabled:=true;
N16.Enabled:=true;

end else
begin
N15.Enabled:=false;
N16.Enabled:=false;

end;
if qx[3] then
begin
N11.Enabled:=true;
N12.Enabled:=true;
N13.Enabled:=true;

end
else
begin
N11.Enabled:=false;
N12.Enabled:=false;
N13.Enabled:=false;

end;
if qx[4] then
begin
N18.Enabled:=true;
N19.Enabled:=true;

N20.Enabled:=true;

end
else
begin
N18.Enabled:=false;
N19.Enabled:=false;

N20.Enabled:=false;

end;
end
else
close;

end;
red]下面的TtreeviewChange的代码?[/red]
procedure TMainForm.TreeView1Change(Sender: TObject; Node: TTreeNode);
begin
// Node.SelectedIndex:=1;
// if qx[1] then
// begin
// TreeView1.Selected.Text
// end;

if TreeView1.Selected.Text='教材入库' then
frmBookIn.ShowModal();
if TreeView1.Selected.Text='操作员管理' then
frmOperator.ShowModal();
if TreeView1.Selected.Text='库存查询' then
bookbrowerform.ShowModal();
if TreeView1.Selected.Text='单位信息' then
UnitForm.ShowModal();
if TreeView1.Selected.Text='密码修改' then
passwordchangeform.ShowModal();
if TreeView1.Selected.Text='班级管理' then
classform.ShowModal();
if TreeView1.Selected.Text='缴纳书费' then
BookFeeForm.ShowModal;
if TreeView1.Selected.Text='退回书费' then
ReturnFeeForm.ShowModal;


end;
[red]请问如何获得Ttreenode结点,根据权限qx,使它的.enable属性为false[/red]
 
一个小系统,用Ttreeview把菜单的各项都显示出来了.
可是菜单是根据不同用户的权限来显示,但Ttreeview如何才能实现?


qx:array [1..4] of boolean;分配四种不同的权限.
var
MainForm: TMainForm;
username:string;
qx:array [1..4] of boolean;
i:Integer;
implementation
uses uLogin, uBooiIn,uOperator,BookBrower,units, PasswordChange,classmanage,bookfee,
returnfee;

{$R *.dfm}

procedure TMainForm.FormActivate(Sender: TObject);
//var
// i:Integer;
begin
frmLogin.ShowModal;
if Right=False then
begin
for i:=0 to 3 do
begin
// if (i<>4) and (Right=False) then
frmLogin.ShowModal;
if Right=True then Break;
end
end;

if username<>'' then
begin
if qx[1] then[red]这里是菜单的权限分配[/red]
begin
N2.Enabled:=true;
N3.Enabled:=true;
N4.Enabled:=true;
N6.Enabled:=true;
N7.Enabled:=true;
N9.Enabled:=true;

end else
begin
N2.Enabled:=false;
N3.Enabled:=false;
N4.Enabled:=false;
N6.Enabled:=false;
N7.Enabled:=false;
N9.Enabled:=false;

end;
if qx[2] then
begin
N15.Enabled:=true;
N16.Enabled:=true;

end else
begin
N15.Enabled:=false;
N16.Enabled:=false;

end;
if qx[3] then
begin
N11.Enabled:=true;
N12.Enabled:=true;
N13.Enabled:=true;

end
else
begin
N11.Enabled:=false;
N12.Enabled:=false;
N13.Enabled:=false;

end;
if qx[4] then
begin
N18.Enabled:=true;
N19.Enabled:=true;

N20.Enabled:=true;

end
else
begin
N18.Enabled:=false;
N19.Enabled:=false;

N20.Enabled:=false;

end;
end
else
close;

end;
red]下面的TtreeviewChange的代码?[/red]
procedure TMainForm.TreeView1Change(Sender: TObject; Node: TTreeNode);
begin
// Node.SelectedIndex:=1;
// if qx[1] then
// begin
// TreeView1.Selected.Text
// end;

if TreeView1.Selected.Text='教材入库' then
frmBookIn.ShowModal();
if TreeView1.Selected.Text='操作员管理' then
frmOperator.ShowModal();
if TreeView1.Selected.Text='库存查询' then
bookbrowerform.ShowModal();
if TreeView1.Selected.Text='单位信息' then
UnitForm.ShowModal();
if TreeView1.Selected.Text='密码修改' then
passwordchangeform.ShowModal();
if TreeView1.Selected.Text='班级管理' then
classform.ShowModal();
if TreeView1.Selected.Text='缴纳书费' then
BookFeeForm.ShowModal;
if TreeView1.Selected.Text='退回书费' then
ReturnFeeForm.ShowModal;


end;
[red]请问如何获得Ttreenode结点,根据权限qx,使它的.enable属性为false[/red]
 
你使用RC3的一组控件,里面有treeview_Checked就可以了!
 
定义一下Node.Data指针类型 把权限放里面动态判断
QQ群11105482
 
如何才能知道treeview控件的名柄呢
 
看看这个是不是你想要的!
procedure TMainForm.TreeView1Change(Sender: TObject; Node: TTreeNode);
var
TreeData: PDataTreeItem;
sItem :string;
begin
if Node.Level <> 0 then
begin
TreeData := PDataTreeItem(Node.Data);
sItem := TreeData^.No;
end;
end;
 
谢谢大家回帖,问题还没有解决,继续啊
 
多人接受答案了。
 
后退
顶部