50分,再求兩個BCB轉delphi的問題,非常感謝! Delphi / Windows SDK/APIhttp://www.delphi2007.net/DelphiDB/html/delphi_20061218201812234.html
下面兩段代碼如何轉成 delphi 的,多謝
1.
int Command, i;
AnsiString Name,Desc;
TLocateOptions Opts;
Opts.Clear();
Opts << loCaseInsensitive;
for (i = 0; i < ComponentCount; i++)
{
if (dynamic_cast<TMenuItem*>(Components[i]))
{
if (!MENUENABLEDataSet->Locate("MENU",dynamic_cast<TMenuItem*>(Components[i])->Name,Opts))
{
dynamic_cast<TMenuItem*>(Components[i])->Enabled = false;
}
}
}
2.
int i,Command;
AnsiString Name,Desc;
for (i=0;i<ComponentCount;i++)
{
if (dynamic_cast<TMenuItem*>(Components[i]))
{ //<指標 void* 定義過的類別> (指標 參考)
Command = dynamic_cast<TMenuItem*>(Components[i])->Command;
Desc = dynamic_cast<TMenuItem*>(Components[i])->Caption;
Name = dynamic_cast<TMenuItem*>(Components[i])->Name;
MENUDataSet->InsertRecord(ARRAYOFCONST((Command,Name,Desc)));
}
}
ShowMessage("菜單重置完成!");
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元件只是为求代码通过加上去的,如果使用它们会出错;过程名称随便取的;只是直接将代码移植过来,其它未加考虑。
還沒空測試,先買單,多謝了!