?? syspublictmp.pas
字號:
end;
DataGrid.Columns[i].SummaryFooterType := aType;
DataGrid.Columns[i].SummaryFooterField := Trim(FieldByName('col_foot_field').AsString);
DataGrid.Columns[i].SummaryFooterFormat := Trim(FieldByName('col_foot_format').AsString);
end;
if FieldByName('col_display_format').AsString <> '' then
(DataGrid.Columns[i] as TdxDBGridCurrencyColumn).DisplayFormat := FieldByName('col_display_format').AsString;
DataGrid.Columns[i].BandIndex := 0;
DataGrid.Columns[i].FieldName := Trim(FieldByName('col_field_name').AsString);
DataGrid.Columns[i].Caption := Trim(FieldByName('col_text').AsString);
DataGrid.Columns[i].ReadOnly := FieldByName('col_read_only').AsInteger > 0;
DataGrid.Columns[i].Width := FieldByName('col_width').AsInteger;
Next;
Inc(i);
end;
end;
ColQuery.Close;
finally
ColQuery.Free;
end;
end;
}
{
參考我的代碼
//如果控件具有UIStyle屬性,則設置其值
//UIStyle屬性為枚舉類型
function SetComponentUIStyle(AComponent :TComponent; AUIStyle : TUIStyle) :Boolean;
var
PropInfo :PPropInfo;
FStyle :String;
begin
Result := False;
PropInfo := GetPropInfo(AComponent.ClassInfo, 'UIStyle');
if PropInfo <> nil then
begin
if PropInfo^.PropType^.Kind= tkEnumeration then
begin
FStyle := GetEnumName(TypeInfo(TsuiUIStyle), Integer(AUIStyle));
SetEnumProp(AComponent, PropInfo, FStyle);
Result := True;
end;
end;
end;
function SetComponentFileTheme(AComponent :TComponent; AFileTheme: TFileTheme) :Boolean;
var
PropInfo :PPropInfo;
begin
Result := False;
PropInfo := GetPropInfo(AComponent.ClassInfo, 'FileTheme');
if PropInfo <> nil then
begin
if PropInfo^.PropType^.Kind= tkClass then
begin
SetObjectProp(AComponent, PropInfo, AFileTheme);
Result := True;
end;
end;
end;
}
{
寫了一個函數,試試看
function CheckEditInt(AEdit:TEdit;Min,Max:Integer;CanNull:Boolean;Info:string):Integer;
TempInt:integer;
TempStr:string;
begin
try
if CanNull=True then
begin
if Trim(AEdit.Text)='' then
begin
Result:=0;
exit;
end;
end
else
if Trim(AEdit.Text)='' then
begin
Result:=1;
ShowMessage(Info+'不能為空!');
AEdit.SetFocus;
exit;
end;
TempInt:=StrToInt(AEdit.Text);
if (TempInt<Min) or (TempInt>Max) then
begin
if Min=Max then
TempStr:=IntToStr(Min)+'!'
else
TempStr:=IntToStr(Min)+'至'+IntToStr(Max)+'之間!';
ShowMessage(Info+'必需為'+TempStr);
Result:=2;
exit;
end;
Result:=0;
Except
ShowMessage(Info+'應為數字!');
AEdit.SetFocus;
Result:=1;
end;
end;
}
{
procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
Temp: TComponent;
begin
for I := 0 to ComponentCount - 1 do
begin
Temp := Components[I];
if Temp is TEdit then
begin
TEdit(Temp).ReadOnly := true;
end;
end;
end;
或者:
procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
begin
for I := 0 to ControlCount - 1 do
begin
if Controls[I] is TEdit then
begin
TEdit(Controls[I]).ReadOnly := true;
end;
end;
end;
}
{
frreport1.LoadFromFile(extractfilepath(application.exename)+'1.frf');
FrReport1.PrepareReport;
FrReport1.PrintPreparedReport('1',1,True,frAll); .//直接打印
frreport1.ShowReport; //進入預覽窗體
frreport1.DesignReport;
}
{
問題:求根據數據庫動態生成菜單的代碼 ( 積分:50, 回復:8, 閱讀:145 )
分類:數據庫-文件型 ( 版主:hbezwwl, bubble )
來自:oupj, 時間:2004-9-5 13:19:00, ID:2794454 [顯示:小字體 | 大字體]
數據庫結構為
MenuName Caption SetID
————————————————
wrer 文件 10
jhjt 文件1 1010
hj 文件2 1012
fh - 1011
u 編輯 11
ry 編輯1 1110
hjkhhg 編輯2 111011
g 操作 12
怎樣根據以上數據庫生產如下菜單
文件 編輯 操作
|_文件1 |_編輯1
|_文件2 |_編輯2
來自:dlwzp, 時間:2004-9-6 12:50:43, ID:2795314
1)select * from your db order by setid
2)對SetID截位,產生菜單項
其實菜單是一種樹形結構,你能把表還原成樹,就能動態生成菜單。
來自:oupj, 時間:2004-9-8 12:39:58, ID:2798232
我自己有一個,不過有缺點,哪位高手幫忙修修
procedure TFrm_Main.LoadMainMenu;
var
curID: String;
ImageIndex: Integer;
level: Integer;
MainMenuItem, MenuItem: TMenuItem;
//MenuItem: Array[0..9] of TMenuItem;
//MenuItem: TMenuItem;
begin
//初始化變量
level:=0 ;
curID:= '';
//遍歷數據表,利用編碼字段記錄排序規律,依次添加
with CDS_Sys_Menu do
begin
try
Close;
CommandText:= 'Select * from Sys_Menu where SeptID Like '+ QuotedStr(CurID+'%')
+' and Len(SeptID)='+ (IntToStr(Length(curID)+2)) +' order by SeptID';
Open;
First;
while not eof do
begin
curID:=Trim(FieldByName('SeptID').AsString);
begin
if Not FieldByName('ImageIndex').IsNull then
ImageIndex:= FieldByName('ImageIndex').AsInteger;
MainMenuItem:= TMenuItem.Create(MainMenu1);
MainMenuItem.Name:= Trim(FieldByName('MenuName').AsString);
MainMenuItem.Caption:= Trim(FieldByName('Caption').AsString);
MainMenu1.Items.Add(MainMenuItem);
end;
LoadMainItem(MainMenuItem, curID);
Next;
end;
finally;
close;
end;
end;
end;
Function TFrm_Main.LoadMainItem(MainMenuItem: TMenuItem;curID: String) :Integer;
var
MenuItem: TMenuItem;
begin
with CDS_Tmp do
begin
Close;
CommandText:= 'Select * from Sys_Menu where SeptID Like '+ QuotedStr(CurID+'%')
+' and Len(SeptID)='+ (IntToStr(Length(curID)+2)) +' order by SeptID';
Open;
while not eof do
begin
MenuItem:= TMenuItem.Create(MainMenu1);
MenuItem.Name:= Trim(FieldByName('MenuName').AsString);
MenuItem.Caption:= Trim(FieldByName('Caption').AsString);
MainMenuItem.Add(MenuItem);
LoadMainItem(MenuItem, Trim(CDS_Tmp.FieldByName('SeptID').AsString));
Next;
end;
end;
end;
來自:flamboyant, 時間:2004-9-8 13:19:26, ID:2798318
procedure TFrm_Main.LoadMainMenu;
var
curID: String;
level: Integer;
MenuItem: TMenuItem;
begin
//初始化變量
level:=-1 ;
curID:= '';
//遍歷數據表,利用編碼字段記錄排序規律,依次添加
with CDS_Sys_Menu do
begin
try
Close;
CommandText:= 'Select * from Sys_Menu order by SeptID';
Open;
First;
while not eof do
begin
MainMenuItem:= TMenuItem.Create(MainMenu1);
begin
if length(FieldByName('SeptID').AsString)=2 then
begin
curID:=Trim(FieldByName('SeptID').AsString);
level:=level+1
MainMenuItem.Name:= Trim(FieldByName('MenuName').AsString);
MainMenuItem.Caption:= Trim(FieldByName('Caption').AsString);
MainMenu1.Items.Add(MainMenuItem);
end
else
begin
if curid=left(Trim(FieldByName('MenuName').AsString),2) then
begin
MainMenuItem.Name:= Trim(FieldByName('MenuName').AsString);
MainMenuItem.Caption:= Trim(FieldByName('Caption').AsString);
MainMenu1.Items[level].Add(MainMenuItem);
end;
end;
end;
end;
finally;
close;
end;
end;
end;
end;
沒試,大概改了下。對不符合規頂的記錄沒有處理
來自:hongxing_dl, 時間:2004-9-8 13:34:47, ID:2798341
這個問題還沒解決嗎???幾天前看到的,那時候寫好了都沒發出去就斷網了,今天再發:
首先放一個MainMenu在窗體上:
procedure TForm1.FormCreate(Sender: TObject);
var
mi,mi_sub:tmenuitem;
mi_name:string;
begin
dataset.close;
//這里將數據查詢出來//我用dataset來代替,可以照dlwzp說的排個序
dataset.open;
while not dataset.eof do
begin
mi_sub:=tmenuitem.create(self);
mi_sub.caption:=dataset.fieldbyname('caption').asstring;
mi_sub.name:='Menu_'+dataset.fieldbyname('SetID').asstring;
mi_name:=copy(mi_sub.name,1,length(mi_sub.name)-2);
mi:=nil;
if findcomponent(mi_name)<>nil then
mi:= findcomponent(mi_name) as tmenuitem;
if mi=nil then//表示沒有父類菜單,則添加到主菜單,否則添加到相應的菜單下面
mainmenu1.Items.Add(mi)
else
mi.add(mi_sub);
dataset.next;//下一項菜單
end;
end;
可能不是很全面,樓主自己再強化一下吧:) 已經很簡化了
來自:oupj, 時間:2004-9-8 15:24:06, ID:2798563
感謝上面2位朋友的幫助
但很可惜,都不行,:)
來自:zhfree, 時間:2004-9-8 15:36:21, ID:2798578
朋友再多加個字段,最終類似:id,父id,name,。。。。
目錄項的記錄父id都為零,子項記錄的父id記錄上級記錄的id;
最后一個select語句,一個循環,配合菜單項的創建即可完成
來自:flamboyant, 時間:2004-9-9 15:39:58, ID:2800177
procedure TFrm_Main.LoadMainMenu;
var
curID: String;
level: Integer;
MenuItem: TMenuItem;
begin
//初始化變量
level:=-1 ;
curID:= '';
//遍歷數據表,利用編碼字段記錄排序規律,依次添加
with CDS_Sys_Menu do
begin
try
Close;
CommandText:= 'Select * from Sys_Menu order by SeptID';
Open;
First;
while not eof do
begin
MenuItem:= TMenuItem.Create(self);
begin
if length(trim(FieldByName('SeptID').AsString))=2 then
begin
curID:=Trim(FieldByName('SeptID').AsString);
level:=level+1;
MenuItem.Name:= Trim(FieldByName('MenuName').AsString);
MenuItem.Caption:= Trim(FieldByName('Caption').AsString);
MainMenu1.Items.Add(MenuItem);
end
else
begin
if curid=leftstr(Trim(FieldByName('SeptID').AsString),2) then
begin
MenuItem.Name:= Trim(FieldByName('MenuName').AsString);
MenuItem.Caption:= Trim(FieldByName('Caption').AsString);
MainMenu1.Items[level].Add(MenuItem);
end;
end;
end;
next;
end;
finally;
close;
end;
end;
end;
這次試過了,就是排除了幾個低級錯誤。樓主應該有點探索精神,自己動動手,
來自:oupj, 時間:2004-9-10 8:28:06, ID:2800976
樓上的你請試清楚
不是我懶,而是你的代碼不能生成多級菜單
}
{
父類 protected 里申明的變量或函數對他的子類是開放的,其他的類是不能訪問的。
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -