然后用下列程序。他可以显示MENU的数据到TREEVIEW,并开始做维护。我只做了增加子菜单,其余的比较简单。
type
Pmyrec = ^TMyRec;
TMyRec = record
menu_id: string;
end;
//关键是这段
procedure Tw_menu_wf.FormCreate(Sender: TObject);
var
j1,j2,n:integer;
mynode,subnode:ttreenode;
p
_menu_wf.PMYREC;
begin
dm1.menu1.Open;
dm1.models.open;
dm1.menu1.IndexName:='PK_LOC';
dm1.menu1.First;
//if dm1.usersUSER_ID.AsInteger <> user_id
j1:=0;
tv1.Items.Clear;
NEW(P);
P^.menu_id:=('999999');
subnode:=tv1.items.Addobject(nil,'开始',P);
mynode:=subnode;
while not dm1.menu1.Eof do
begin
if dm1.menu1user_id.AsInteger = user_id then
begin
NEW(P);
//--------------
j2:= dm1.menu1menu_grade.asinteger;
case j2-j1 of
0: //同级
begin
P^.menu_id:=(dm1.menu1menu_id.ASSTRING);
subnode:=tv1.items.Addchildobject(myNode,dm1.menu1menu_name.asstring,P);
end;
1: //下级
begin
mynode:=subnode;
P^.menu_id:=(dm1.menu1menu_id.ASSTRING);
subnode:=tv1.items.Addchildobject(myNode,dm1.menu1menu_name.asstring,P);
end;
-300000..-1: //上级
begin
for n :=0 to j1-j2 do
begin
subnode:=subnode.Parent;
end;
mynode:=subnode;
P^.menu_id:=(dm1.menu1menu_id.ASSTRING);
subnode:=tv1.items.Addchildobject(myNode,dm1.menu1menu_name.asstring,P);
end;
else //数据有错
begin
showmessage('数据有错误');
end;
end;
//--------------
j1:=j2;
end;
dm1.menu1.next;
if dm1.menu1.Eof then break;
end;
tv1.FullExpand;
end;
...