从数据库中读数据建立菜单
来源:互联网 发布:amx105突击型数据 编辑:程序博客网 时间:2024/06/03 02:45
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, DB, ADODB, StdCtrls;
type
PMenuRecord = ^TMenuRecord;
TMenuRecord = Record
MenuId:string[20];
end;
TForm1 = class(TForm)
MainMenu1: TMainMenu;
ADOConnection1: TADOConnection;
Button1: TButton;
ADOQuery1: TADOQuery;
ADOQuery2: TADOQuery;
N1231: TMenuItem;
N1: TMenuItem;
ADOQuery3: TADOQuery;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
function createItem(s:string;ParentMenu:Tmenuitem;MainMEnu:TMainmenu
;Mid:string):TmenuItem;
procedure createChileItem(mid:string;layer:string;parentItem:TMenuItem);
procedure execItem(sender:Tobject);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.execItem(sender:tobject);
var
mid:string;
adoquery:TAdoquery;
begin
if sender is TMenuItem then
begin
mid := TMenuItem(sender).name;
adoquery := TAdoquery.Create(nil);
adoQuery.Connection := self.ADOConnection1;
try
with adoquery do
begin
sql.Add('select m_name_call from menu where m_id='''+mid+'''');
open;
showmessage(mid);
end;
finally
adoQuery.Free;
end;
end;
end;
function TForm1.createItem(s:string;ParentMenu:Tmenuitem;
MainMEnu:TMainmenu;Mid:string):TMEnuItem;
var
Item1:TMenuItem;
adoquery:TAdoquery;
begin
adoquery := TAdoquery.Create(nil);
adoQuery.Connection := self.ADOConnection1;
item1 := TMenuITem.Create(mainMenu);
item1.Name := mid;
parentMenu.Add(item1);
item1.Caption := s;
result := item1;
try
with adoquery do
begin
sql.Add('select m_name_call from menu where m_id='''+mid+'''');
open;
if Fields[0].IsNull then
item1.OnClick := nil
else
item1.OnClick := self.execItem;
end;
finally
adoquery.Free;
end;
end;
procedure TForm1.createChileItem(mid:string;layer:string;parentItem:TMenuItem);
var
Adoquery:TAdoQuery;
aItem:TMenuitem;
begin
adoquery := TAdoquery.Create(nil);
adoquery.Connection := self.ADOConnection1;
try
with adoquery do
begin
sql.Add('select m_id,M_name from menu where m_parent_id='''+mid+'''');
open;
while not eof do
begin
aItem:=self.createItem(fields[1].AsString,parentItem,self.MainMenu1,Fields[0].asstring);
self.createChileItem(Fields[0].asstring,'1',aItem);
next;
end;
end;
finally
AdoQuery.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
menuRecord:PMenuRecord;
mid : string;
aItem:TMenuitem;
i:integer;
begin
with adoQuery1 do
begin
if active then close;
sql.Clear;
sql.Add('select M_Id,M_name from Menu where M_layer=1');
open;
i:=2;
while not eof do
begin
mid := fields[0].AsString;
aitem:=self.createItem(Fields[1].asstring,self.MainMenu1.Items,self.MainMenu1,mid);
aitem.MenuIndex := i;
self.createChileItem(Fields[0].asstring,'2',aItem);
next;
i:=i+1;
end;
end;
n1.MenuIndex := i; //改变菜单的位置
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
n1231.MenuIndex :=1;
end;
end.
- 从数据库中读数据建立菜单
- 从access数据库中读数据建立tree
- 从数据库中读数据
- WR 从数据库读数据到Excel中
- 从excel读数据到数据库表中
- 从sql数据库中读数据来创建tree
- 从外部配置文件中读数据库语句查询数据库
- Android数据库代码优化(3) - 从Cursor中读数据
- Spark从数据库读数据操作
- fgets()函数从文件中读数据
- 网页从xml文件中读数据
- storm从kafka中读数据
- 从text文件中读数据
- sql server compact 从数据库中读数据并显示图片
- 编程方式从数据库建立TreeView菜单
- 从文件读数据
- Qgis从数据库读数据到渲染当前视图
- 从csv中读数据,并写到csv中
- 8.3 声明符的含义
- MD5之C语言源代码
- 美化你的菜单
- 个人职业生涯规划发展的一些图
- datagrid 设定列宽
- 从数据库中读数据建立菜单
- C++中的类型转换与类型识别 2
- 今天不错哦!
- c++中const的作用- -
- 什么是BPM
- BPM业务流程管理的关键功能
- Writing a Winsock 2 Layered Service Provider(LSP) 译文(zz)
- 信息部门人员角色划分及任职资格
- IRC聊天工具常用命令(小卡片)