從資料庫中讀資料建立選單

2021-04-06 20:12:05 字數 3689 閱讀 9971

unit unit1;

inte***ce

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

end;

varform1: tform1;

implementation

procedure tform1.execitem(sender:tobject);

varmid:string;

adoquery:tadoquery;

begin

if sender is tmenuitem then

begin

mid := tmenuitem(sender).name;

adoquery := tadoquery.create(nil);

adoquery.connection := self.adoconnection1;

trywith 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;

varitem1: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;

trywith 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);

varadoquery:tadoquery;

aitem:tmenuitem;

begin

adoquery := tadoquery.create(nil);

adoquery.connection := self.adoconnection1;

trywith 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);

varmenurecord: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.

利用pymysql從資料庫中讀資料,並存取list

def read data from db 連線配置資訊 db pymysql.connect host port user password db charset utf8 cursorclass pymysql.cursors.dictcursor 建立連線 con pymysql.connec...

從資料庫動態載入選單

一 資料庫設計 系統選單表 column type comment idint 選單編號 menu name varchar 一級選單名 menu num varchar 所屬的一級選單編號 picture varchar 選單url varchar 選單連結 is use int是否使用 sort...

資料庫 Oracle中建立資料庫

create database lihua 網上的說法是 oracle中的例項只對應一個資料庫,出現此種情況說明oracle資料庫處於mount 裝載 或open狀態,需要使用startup nomount語句進行狀態更改,或者是直接使用dbca的圖形介面來建立 注 經測試,startup nomo...

從Access建立Sqlite資料庫

首先,我們需要使用sqlite expert professional 工具 1 建立一個新的資料庫 2 由sqlite expert建立資料庫。然後import data transfer wizard import data into.ado data source 3 資料來源選擇 provi...

從資料庫讀出資料動態生成選單欄

注 這個是當初水平有限比較初級的 後來後來 就 有相對高階點的參考 dbunitly層 using system using system.collections.generic using system.linq using system.text using system.data.sqlcli...