⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 syspublictmp.pas

📁 蓝图财务进销存一体化,delphi源码,使用ACCESS数据库
💻 PAS
📖 第 1 页 / 共 3 页
字号:
          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 + -