계속해서 에러가 나네요 데이터 파일의 내용은
1파일(&a)
2새로만들기(&b)
2저장(&c)
3일반저장(&d)
3암호저장(&e)
3엑셀저장(&f)
이런 식으로 만들었거든요
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Menus;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
mainmenu:TMainMenu;
MainItems, SubItems, SubItems1 :array of TMenuItem;
MenuItemsFile: TextFile;
ItemsString:String;
FirstChar:byte;
MainItemsCount,SubItemsCount,SubItemsCount1:word;
begin
assignFile(MenuItemsFile,'MenuItems.txt');
{$i-}
reset(MenuItemsFile);
{$i+}
if IOResult<>0 then begin
messageDlg('메뉴아이템 파일에 이상이 있습니다.'#13#13'확인 바랍니다',mtError,[mbOK],0);
exit
end;
MainItemsCount:=0;
repeat
readln(menuItemsFile,ItemsString);
FirstChar:=strtointdef(copy(ItemsString,1,1),0);
case FirstChar of
1:
begin
SubItemsCount:=1;
inc(MainItemsCount);
setLength(MainItems,MainItemsCount);
MainItems[MainItemsCount-1]:=TMenuItem.Create(self);
MainItems[MainItemsCount-1].Name:=format('a%d',[MainItemsCount]);
MainItems[MainItemsCount-1].Caption:=copy(ItemsString,2,length(ItemsString));
end;
2:
begin
SubItemsCount1:=SubItemsCount;
setLength(SubItems,SubItemsCount);
SubItems[SubItemsCount-1]:=TMenuItem.Create(self);
SubItems[SubItemsCount-1].Name:=format(chr(MainItemsCount+66)+'%d',[SubItemsCount]);
SubItems[SubItemsCount-1].Caption:=copy(ItemsString,2,length(ItemsString));
MainItems[MainItemsCount-1].Add(SubItems[SubItemsCount-1]);
inc(SubItemsCount);
end;
3:
begin
setLength(SubItems1,SubItemsCount1);
SubItems1[SubItemsCount1-1]:=TMenuItem.Create(self);
SubItems1[SubItemsCount1-1].Name:=format(chr(SubItemsCount+66)+'%d',[SubItemsCount1]);
SubItems1[SubItemsCount1-1].Caption:=copy(ItemsString,2,length(ItemsString));
SubItems[SubItemsCount-1].Add(SubItems1[SubItemsCount1-1]);
inc(SubItemsCount1);
end;
end;
until eof(MenuItemsFile);
closeFile(MenuItemsFile);
MainMenu:=TmainMenu.Create(Form1);
MainMenu.AutoHotkeys:=maManual;
MainMenu.Items.Add(MainItems);
end;
그냥 다시 짰습니다.. -_-;;
근데 예외고 뭐고 그냥 짠거라 그대로 쓰시기 보단 좀 생각해 보시고
쓰시는게 좋을 꺼 같습니다.. ^^
암튼 소스 올립니다..
그럼 문제 있음 질문해 주세요..
////////////////////////////////////////////////////////////////////
procedure TForm1.Button1Click(Sender: TObject);
var
mainmenu:TMainMenu;
MainItem, SubItem1, SubItem2 : TMenuItem;
MenuItemsFile: TextFile;
ItemsString:String;
FirstChar:byte;
begin
assignFile(MenuItemsFile,'MenuItems.txt');
{$i-}
reset(MenuItemsFile);
{$i+}
if IOResult<>0 then begin
messageDlg('메뉴아이템 파일에 이상이 있습니다.'#13#13'확인 바랍니다',mtError,[mbOK],0);
exit
end;
MainMenu:=TmainMenu.Create(Form1);
MainMenu.AutoHotkeys:=maManual;
repeat
readln(menuItemsFile,ItemsString);
FirstChar:=strtointdef(copy(ItemsString,1,1),0);
case FirstChar of
1:
begin
MainItem := NewItem(copy(ItemsString,2,length(ItemsString)),0,false,true,nil,0,'');
MainMenu.Items.Add(MainItem);
end;
2:
begin
SubItem1 := NewItem(copy(ItemsString,2,length(ItemsString)),0,false,true,nil,0,'');
MainItem.Add(SubItem1);
end;
3:
begin
SubItem2 := NewItem(copy(ItemsString,2,length(ItemsString)),0,false,true,nil,0,'');
SubItem1.Add(SubItem2);
end;
end;
until eof(MenuItemsFile);
closeFile(MenuItemsFile);
end;