L
LeonSu
Unregistered / Unconfirmed
GUEST, unregistred user!
源程序如下:
procedure TForm1.LoadMenuItem(var aMenuList: array of TMenuItem);
var
RFile: TIniFile;
I: Integer;
S: String;
begin
RFile:=TIniFile.Create(ChangeFileExt(Application.ExeName,'.ini'));
Try
For I:=0 to high(aMenuList)-1 do
begin
S:=RFile.ReadString('Recent File','Rec'+IntToStr(I),'');
If S<>'' then
begin
aMenuList:=TMenuItem.Create(Self);
With aMenuList do
begin
Caption:=Format('&%d %s',[I,S]);
Name:='Recent'+IntTostr(I);
OnClick:=MyMenuItemClick;
end;
end;
end;
Finally
RFile.Free;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
aMenuItem: array[0..9] of TMenuItem;
begin
LoadMenuItem(aMenuItem);
RecFile1.Add(aMenuItem);
end;
从外部的INI文件中读取字串,生成一个子菜单数组最后一次性插入到一个固定的菜单(RecFile1)中,
插入是成功了,但每次都要说:menu insert twice!菜单插入了两次,搞不懂,
把代码改为一个个的读取、插入就没问题了
请大虾指教。
procedure TForm1.LoadMenuItem(var aMenuList: array of TMenuItem);
var
RFile: TIniFile;
I: Integer;
S: String;
begin
RFile:=TIniFile.Create(ChangeFileExt(Application.ExeName,'.ini'));
Try
For I:=0 to high(aMenuList)-1 do
begin
S:=RFile.ReadString('Recent File','Rec'+IntToStr(I),'');
If S<>'' then
begin
aMenuList:=TMenuItem.Create(Self);
With aMenuList do
begin
Caption:=Format('&%d %s',[I,S]);
Name:='Recent'+IntTostr(I);
OnClick:=MyMenuItemClick;
end;
end;
end;
Finally
RFile.Free;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
aMenuItem: array[0..9] of TMenuItem;
begin
LoadMenuItem(aMenuItem);
RecFile1.Add(aMenuItem);
end;
从外部的INI文件中读取字串,生成一个子菜单数组最后一次性插入到一个固定的菜单(RecFile1)中,
插入是成功了,但每次都要说:menu insert twice!菜单插入了两次,搞不懂,
把代码改为一个个的读取、插入就没问题了
请大虾指教。