全部博文(788)
分类:
2009-02-19 17:03:24
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBTables, Menus;
type
TForm1 = class(TForm)
MENUENABLEDataSet: TTable; //测试用
MENUDataSet: TTable; //测试用
private
{ Private declarations }
public
{ Public declarations }
procedure Proc1;
procedure Proc2;
end;
var
Form1: TForm1;
implementation
//uses DB;
{$R *.dfm}
{ TForm1 }
procedure TForm1.Proc1;
var
i: Integer;
Opts: TLocateOptions;
// Name, Desc: string;
begin
Opts := [];
Include(Opts, loCaseInsensitive);
for i := 0 to ComponentCount - 1 do
begin
if Components[i] is TMenuItem then
if not MENUENABLEDataSet.Locate('MENU', TMenuItem(Components[i]).Name, Opts) then
TMenuItem(Components[i]).Enabled := False;
end;
end;
procedure TForm1.Proc2;
var
Command, i: Integer;
Name, Desc: string;
begin
for i := 0 to ComponentCount - 1 do
begin
if Components[i] is TMenuItem then
begin
//<指標 void* 定義過的類別> (指標 參考)
Command := TMenuItem(Components[i]).Command;
Desc := TMenuItem(Components[i]).Caption;
Name := TMenuItem(Components[i]).Name;
MENUDataSet.InsertRecord([Command,Name,Desc]);
end;
end;
ShowMessage('菜單重置完成!');
end;
end.
注意,前面2个TTable元件只是为求代码通过加上去的,如果使用它们会出错;过程名称随便取的;只是直接将代码移植过来,其它未加考虑。
還沒空測試,先買單,多謝了!