看看这段代码吧???

时间:2022-03-11 21:07:17
NewMenuItem := TMenuItem.Create(self);

  if FileExists(ExtractFilePath(paramstr(0))+'RZCL.ini') then
  begin
    fIniFile := TIniFile.Create(ExtractFilePath(paramstr(0))+'RZCL.ini');
    NewMenuItem.Caption := fIniFile.ReadString('ReceiveFileLists','stair','');
    MainMenu1.Items[0].Items[0].Add(NewMenuItem);
  end;
  fIniFile.Free;
INI文件的stair=ppp,为何caption却读不出来呢。

13 个解决方案

#1


INI的格式应该是
[ReceiveFileLists]
stair=ppp
检查一下
有没有错误
最好用TiniFile的write方法写入以保证可靠性

#2


没错呀,我就是这样干的。var
  ini:TIniFile;
begin
  if FileExists(ExtractFilePath(paramstr(0))+'RZCL.ini') then exit;

  try
    ini:=TIniFile.Create(ExtractFilePath(paramstr(0))+'RZCL.ini');
    ini.WriteString('ReceiveFileList','stair', '');
    ini.WriteString('SengFileList','square','');
    ini.WriteString('ReceiveFileList','debt', '');
    ini.WriteString('SengFileList','busin','');
    ini.WriteString('ReceiveFileList','order', '');
    ini.WriteString('SengFileList','order_confirm','');
    ini.WriteString('ReceiveFileList','withdraw', '');
    ini.WriteString('SengFileList','withdraw_back','');
    ini.WriteString('ReceiveFileList','rights', '');
    ini.WriteString('SengFileList','trusteeship','');
    ini.WriteString('ReceiveFileList','trans_trust', '');
    ini.WriteString('SengFileList','comparison','');
    ini.WriteString('ReceiveFileList','sz_pg', '');
    ini.WriteString('SengFileList','sh_g4','');
    ini.WriteString('ReceiveFileList','sh_g5', '');
    ini.WriteString('SengFileList','sh_g9','');
    ini.WriteString('ReceiveFileList','sh_g7', '');
    ini.WriteString('SengFileList','sh_g8','');
    ini.WriteString('ReceiveFileList','sz_hm', '');
  finally
    ini.Free;
  end;
可就是不行,奇了怪了?

#3


try this
stair="ppp"

#4


就是不行呀

#5


拜托
ini.WriteString('ReceiveFileList','stair', '');
你写入的stair为空
改成ini.WriteString('ReceiveFileList','stair', 'ppp');
就可以了

#6


我早就在我的程序里做过这种测试了,也不行的。真是奇怪得很。

#7


'ReceiveFileLists','stair'
'ReceiveFileList','stair'

//一个有“s”、一个没有

#8


'ReceiveFileLists','stair'
'ReceiveFileList','stair'

//一个有“s”、一个没有

#9


//都是粗心惹的祸

'ReceiveFileLists','stair'
'ReceiveFileList','stair'

//一个有“s”、一个没有

#10


Ini文件操作应该没问题,不知你是要在第一列菜单中加一项,还是加一子菜单项,按你现在做法
NewMenuItem.Caption; 
就是
MainMenu1.Items[0].Items[0].Items[0].Caption;

或许你应该用MainMenu1.Items[0]Add(NewMenuItem);
便可在一级菜单项中看到NewMenuItem.Caption。

#11


unit Rzcl;

interface

uses
  Windows, Messages, IniFiles, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, ToolWin, ActnMan, ActnCtrls, ActnMenus, ImgList, ShellAPI,
  BandActn, StdActns, ExtActns, ActnList, fcOutlookList, fcButton,
  fcImgBtn, fcShapeBtn, fcClearPanel, fcButtonGroup, fcOutlookBar, ComCtrls,
  XPMenu, Menus, fcLabel, fcImager, fcStatusBar, TFlatCheckListBoxUnit,
  TFlatButtonUnit, StdCtrls;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Image4: TImage;
    MainMenu1: TMainMenu;
    FileMenu: TMenuItem;
    FileNewItem: TMenuItem;
    FileOpenItem: TMenuItem;
    FileSaveItem: TMenuItem;
    FileSaveAsItem: TMenuItem;
    N1: TMenuItem;
    FilePrintItem: TMenuItem;
    N4: TMenuItem;
    FileExitItem: TMenuItem;
    View1: TMenuItem;
    Normal1: TMenuItem;
    PageBreak1: TMenuItem;
    PrintLayout1: TMenuItem;
    Outline1: TMenuItem;
    N3: TMenuItem;
    TaskPane1: TMenuItem;
    ToolBars1: TMenuItem;
    A1: TMenuItem;
    Ruler1: TMenuItem;
    DocumentMap1: TMenuItem;
    N6: TMenuItem;
    HeaderandFooter1: TMenuItem;
    Footnotes1: TMenuItem;
    Markip1: TMenuItem;
    FullScreen1: TMenuItem;
    Zoom1: TMenuItem;
    HelpMenu: TMenuItem;
    HelpItem: TMenuItem;
    OtherHelp1: TMenuItem;
    HelpAboutItem: TMenuItem;
    XPMenu1: TXPMenu;
    ImageList2: TImageList;
    Panel3: TPanel;
    Panel5: TPanel;
    fcStatusBar1: TfcStatusBar;
    Panel4: TPanel;
    fcOutlookBar1: TfcOutlookBar;
    fcOutlookBar1fcShapeBtn1: TfcShapeBtn;
    fcOutlookBar1OutlookList1: TfcOutlookList;
    Panel6: TPanel;
    ToolBar1: TToolBar;
    fcOutlookBar1OutlookList2: TfcOutlookList;
    fcOutlookBar1fcShapeBtn3: TfcShapeBtn;
    fcOutlookBar1OutlookList3: TfcOutlookList;
    fcOutlookBar1fcShapeBtn4: TfcShapeBtn;
    N10: TMenuItem;
    N11: TMenuItem;
    N12: TMenuItem;
    B1: TMenuItem;
    B2: TMenuItem;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    TabSheet3: TTabSheet;
    Panel7: TPanel;
    ListView1: TListView;
    Panel8: TPanel;
    ListView3: TListView;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    N5: TMenuItem;
    N7: TMenuItem;
    Timer1: TTimer;
    procedure Image2Click(Sender: TObject);
    procedure Image3Click(Sender: TObject);
    procedure fcOutlookBar1Enter(Sender: TObject);
    procedure fcOutlookBar1Exit(Sender: TObject);
    procedure FileExitItemClick(Sender: TObject);
    procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormCreate(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N5Click(Sender: TObject);
  private
    procedure CreateiniFile();
    procedure CopyFile(sPathName, sFileName: string);
//    procedure CreateSubMenuItems();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses Add;


{$R *.dfm}

procedure TForm1.CopyFile(sPathName, sFileName: string);
var
  f:TShFileOpStruct;
begin
  F.wnd := Handle;
  F.wFunc := FO_COPY; {操作方式}
  F.pFrom :='d:\1\te14.dbf';
  F.pTo := 'e:\TEmp\te14.dbf';
  if FileExists(sFileName) then
    F.fFlags:=FOF_ALLOWUNDO OR FOF_RENAMEONCOLLISION OR FOF_NOERRORUI

//    F.fFlags := FOF_ALLOWUNDO OR FOF_RENAMEONCOLLISION {操作选项}
  else
    exit;
  try
    ShFileOperation(F);
  except
    ShowMessage('文件拷贝失败!');
  end;
end;

procedure TForm1.CreateIniFile;
var
  ini:TIniFile;
begin
  if FileExists(ExtractFilePath(paramstr(0))+'RZCL.ini') then exit;

  try
    ini:=TIniFile.Create(ExtractFilePath(paramstr(0))+'RZCL.ini');
    ini.WriteString('ReceiveFileList','stair','appp');
    ini.WriteString('SengFileList','square','');
    ini.WriteString('ReceiveFileList','debt', '');
    ini.WriteString('SengFileList','busin','');
    ini.WriteString('ReceiveFileList','order', '');
    ini.WriteString('SengFileList','order_confirm','');
    ini.WriteString('ReceiveFileList','withdraw', '');
    ini.WriteString('SengFileList','withdraw_back','');
    ini.WriteString('ReceiveFileList','rights', '');
    ini.WriteString('SengFileList','trusteeship','');
    ini.WriteString('ReceiveFileList','trans_trust', '');
    ini.WriteString('SengFileList','comparison','');
    ini.WriteString('ReceiveFileList','sz_pg', '');
    ini.WriteString('SengFileList','sh_g4','');
    ini.WriteString('ReceiveFileList','sh_g5', '');
    ini.WriteString('SengFileList','sh_g9','');
    ini.WriteString('ReceiveFileList','sh_g7', '');
    ini.WriteString('SengFileList','sh_g8','');
    ini.WriteString('ReceiveFileList','sz_hm', '');
 {
    stair_path          ,        --一级清算库路径
    square_path        ,        --过户库路径
    debt_path          ,        --回购库路径
    busin_path          ,        --成交回报库路径
    order_path         ,        --委托库路径
    order_confirm_path  ,        --委托确认库路径
    withdraw_path       ,        --委托撤单库路径
    withdraw_back_path  ,        --撤单回报库路径
    rights_path         ,        --权益库路径
    trusteeship_path    ,        --托管库路径
    trans_trust_path    ,        --转托管确认库路径
    comparison_path    ,        --对帐库路径
    sz_pg_path          ,        --配股确认库路径
    sh_g4_path          ,        --上海g4库路径
    sh_g5_path         ,        --上海g5库路径
    sh_g9_path         ,        --上海g9库路径
    sh_g7_path          ,        --上海g7库路径
    sh_g8_path         ,        --上海g8库路径
    sz_hm_path         ,        --深圳hm库路径
}

  finally
    ini.Free;
  end;
end;

function IsUseFile(sFileName : string ) : boolean;
var
  mFile : HFILE;
begin
  Result := false;
  if not FileExists(sFileName) then
    exit;
  mFile := CreateFile(pchar(sFileName), GENERIC_READ or GENERIC_WRITE,0, nil, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, 0);
  Result := (mFile = INVALID_HANDLE_VALUE);
  if not Result then
    CloseHandle(mFile);
end;

procedure TForm1.N5Click(Sender: TObject);
begin
  form2.ShowModal;
end;

procedure TForm1.N2Click(Sender: TObject);
var
  sFileName: string;
  sPathName: string;
begin
  CopyFile(sPathName,sFileName);
end;

procedure TForm1.Image2Click(Sender: TObject);
begin
  Application.Minimize;
end;

procedure TForm1.Image3Click(Sender: TObject);
begin
  Application.Terminate;
end;

procedure TForm1.fcOutlookBar1Enter(Sender: TObject);
begin
  fcOutlookBar1fcShapeBtn1.Font.Color := clBlue;
end;

procedure TForm1.fcOutlookBar1Exit(Sender: TObject);
begin
  fcOutlookBar1fcShapeBtn1.Font.Color := clRed;
end;

procedure TForm1.FileExitItemClick(Sender: TObject);
begin
  Application.Terminate;
end;

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  ReleaseCapture;
  Perform(WM_SYSCOMMAND, SC_MOVE or 1, 0);
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  NewMenuItem: TMenuItem;
  fIniFile: TIniFile;
  a : string;
begin
  CreateIniFile;

  NewMenuItem := TMenuItem.Create(self);

  if FileExists(ExtractFilePath(paramstr(0))+'RZCL.ini') then
  begin
    fIniFile := TIniFile.Create(ExtractFilePath(paramstr(0))+'RZCL.ini');
    NewMenuItem.Caption := fIniFile.ReadString('ReceiveFileLists','stair','');
    MainMenu1.Items[0].Items[0].Add(NewMenuItem);
  end;
  fIniFile.Free;
end;
以上是我的部分原代码。
我有一个主菜单,数据处理,然后下面有文件上传及文件下载两个子菜单,在FormCreate事件中我要根据我的INI 文件生成上传和下载文件清单的子菜单,

#12


可能应该是:
MainMenu1.Items[0].Add(NewMenuItem);
或许,你应该在
MainMenu1.Items[0]的OnClick事件中添加根据INI文件生成的子菜单,不要在FormCreate中生成

#13


在MainMenu1.Items[0]的OnClick事件中添加根据INI文件生成的子菜单就会每次点击时都会发生这个事件,好象不太好吧。

#1


INI的格式应该是
[ReceiveFileLists]
stair=ppp
检查一下
有没有错误
最好用TiniFile的write方法写入以保证可靠性

#2


没错呀,我就是这样干的。var
  ini:TIniFile;
begin
  if FileExists(ExtractFilePath(paramstr(0))+'RZCL.ini') then exit;

  try
    ini:=TIniFile.Create(ExtractFilePath(paramstr(0))+'RZCL.ini');
    ini.WriteString('ReceiveFileList','stair', '');
    ini.WriteString('SengFileList','square','');
    ini.WriteString('ReceiveFileList','debt', '');
    ini.WriteString('SengFileList','busin','');
    ini.WriteString('ReceiveFileList','order', '');
    ini.WriteString('SengFileList','order_confirm','');
    ini.WriteString('ReceiveFileList','withdraw', '');
    ini.WriteString('SengFileList','withdraw_back','');
    ini.WriteString('ReceiveFileList','rights', '');
    ini.WriteString('SengFileList','trusteeship','');
    ini.WriteString('ReceiveFileList','trans_trust', '');
    ini.WriteString('SengFileList','comparison','');
    ini.WriteString('ReceiveFileList','sz_pg', '');
    ini.WriteString('SengFileList','sh_g4','');
    ini.WriteString('ReceiveFileList','sh_g5', '');
    ini.WriteString('SengFileList','sh_g9','');
    ini.WriteString('ReceiveFileList','sh_g7', '');
    ini.WriteString('SengFileList','sh_g8','');
    ini.WriteString('ReceiveFileList','sz_hm', '');
  finally
    ini.Free;
  end;
可就是不行,奇了怪了?

#3


try this
stair="ppp"

#4


就是不行呀

#5


拜托
ini.WriteString('ReceiveFileList','stair', '');
你写入的stair为空
改成ini.WriteString('ReceiveFileList','stair', 'ppp');
就可以了

#6


我早就在我的程序里做过这种测试了,也不行的。真是奇怪得很。

#7


'ReceiveFileLists','stair'
'ReceiveFileList','stair'

//一个有“s”、一个没有

#8


'ReceiveFileLists','stair'
'ReceiveFileList','stair'

//一个有“s”、一个没有

#9


//都是粗心惹的祸

'ReceiveFileLists','stair'
'ReceiveFileList','stair'

//一个有“s”、一个没有

#10


Ini文件操作应该没问题,不知你是要在第一列菜单中加一项,还是加一子菜单项,按你现在做法
NewMenuItem.Caption; 
就是
MainMenu1.Items[0].Items[0].Items[0].Caption;

或许你应该用MainMenu1.Items[0]Add(NewMenuItem);
便可在一级菜单项中看到NewMenuItem.Caption。

#11


unit Rzcl;

interface

uses
  Windows, Messages, IniFiles, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, ToolWin, ActnMan, ActnCtrls, ActnMenus, ImgList, ShellAPI,
  BandActn, StdActns, ExtActns, ActnList, fcOutlookList, fcButton,
  fcImgBtn, fcShapeBtn, fcClearPanel, fcButtonGroup, fcOutlookBar, ComCtrls,
  XPMenu, Menus, fcLabel, fcImager, fcStatusBar, TFlatCheckListBoxUnit,
  TFlatButtonUnit, StdCtrls;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Image4: TImage;
    MainMenu1: TMainMenu;
    FileMenu: TMenuItem;
    FileNewItem: TMenuItem;
    FileOpenItem: TMenuItem;
    FileSaveItem: TMenuItem;
    FileSaveAsItem: TMenuItem;
    N1: TMenuItem;
    FilePrintItem: TMenuItem;
    N4: TMenuItem;
    FileExitItem: TMenuItem;
    View1: TMenuItem;
    Normal1: TMenuItem;
    PageBreak1: TMenuItem;
    PrintLayout1: TMenuItem;
    Outline1: TMenuItem;
    N3: TMenuItem;
    TaskPane1: TMenuItem;
    ToolBars1: TMenuItem;
    A1: TMenuItem;
    Ruler1: TMenuItem;
    DocumentMap1: TMenuItem;
    N6: TMenuItem;
    HeaderandFooter1: TMenuItem;
    Footnotes1: TMenuItem;
    Markip1: TMenuItem;
    FullScreen1: TMenuItem;
    Zoom1: TMenuItem;
    HelpMenu: TMenuItem;
    HelpItem: TMenuItem;
    OtherHelp1: TMenuItem;
    HelpAboutItem: TMenuItem;
    XPMenu1: TXPMenu;
    ImageList2: TImageList;
    Panel3: TPanel;
    Panel5: TPanel;
    fcStatusBar1: TfcStatusBar;
    Panel4: TPanel;
    fcOutlookBar1: TfcOutlookBar;
    fcOutlookBar1fcShapeBtn1: TfcShapeBtn;
    fcOutlookBar1OutlookList1: TfcOutlookList;
    Panel6: TPanel;
    ToolBar1: TToolBar;
    fcOutlookBar1OutlookList2: TfcOutlookList;
    fcOutlookBar1fcShapeBtn3: TfcShapeBtn;
    fcOutlookBar1OutlookList3: TfcOutlookList;
    fcOutlookBar1fcShapeBtn4: TfcShapeBtn;
    N10: TMenuItem;
    N11: TMenuItem;
    N12: TMenuItem;
    B1: TMenuItem;
    B2: TMenuItem;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    TabSheet3: TTabSheet;
    Panel7: TPanel;
    ListView1: TListView;
    Panel8: TPanel;
    ListView3: TListView;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    N5: TMenuItem;
    N7: TMenuItem;
    Timer1: TTimer;
    procedure Image2Click(Sender: TObject);
    procedure Image3Click(Sender: TObject);
    procedure fcOutlookBar1Enter(Sender: TObject);
    procedure fcOutlookBar1Exit(Sender: TObject);
    procedure FileExitItemClick(Sender: TObject);
    procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormCreate(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N5Click(Sender: TObject);
  private
    procedure CreateiniFile();
    procedure CopyFile(sPathName, sFileName: string);
//    procedure CreateSubMenuItems();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses Add;


{$R *.dfm}

procedure TForm1.CopyFile(sPathName, sFileName: string);
var
  f:TShFileOpStruct;
begin
  F.wnd := Handle;
  F.wFunc := FO_COPY; {操作方式}
  F.pFrom :='d:\1\te14.dbf';
  F.pTo := 'e:\TEmp\te14.dbf';
  if FileExists(sFileName) then
    F.fFlags:=FOF_ALLOWUNDO OR FOF_RENAMEONCOLLISION OR FOF_NOERRORUI

//    F.fFlags := FOF_ALLOWUNDO OR FOF_RENAMEONCOLLISION {操作选项}
  else
    exit;
  try
    ShFileOperation(F);
  except
    ShowMessage('文件拷贝失败!');
  end;
end;

procedure TForm1.CreateIniFile;
var
  ini:TIniFile;
begin
  if FileExists(ExtractFilePath(paramstr(0))+'RZCL.ini') then exit;

  try
    ini:=TIniFile.Create(ExtractFilePath(paramstr(0))+'RZCL.ini');
    ini.WriteString('ReceiveFileList','stair','appp');
    ini.WriteString('SengFileList','square','');
    ini.WriteString('ReceiveFileList','debt', '');
    ini.WriteString('SengFileList','busin','');
    ini.WriteString('ReceiveFileList','order', '');
    ini.WriteString('SengFileList','order_confirm','');
    ini.WriteString('ReceiveFileList','withdraw', '');
    ini.WriteString('SengFileList','withdraw_back','');
    ini.WriteString('ReceiveFileList','rights', '');
    ini.WriteString('SengFileList','trusteeship','');
    ini.WriteString('ReceiveFileList','trans_trust', '');
    ini.WriteString('SengFileList','comparison','');
    ini.WriteString('ReceiveFileList','sz_pg', '');
    ini.WriteString('SengFileList','sh_g4','');
    ini.WriteString('ReceiveFileList','sh_g5', '');
    ini.WriteString('SengFileList','sh_g9','');
    ini.WriteString('ReceiveFileList','sh_g7', '');
    ini.WriteString('SengFileList','sh_g8','');
    ini.WriteString('ReceiveFileList','sz_hm', '');
 {
    stair_path          ,        --一级清算库路径
    square_path        ,        --过户库路径
    debt_path          ,        --回购库路径
    busin_path          ,        --成交回报库路径
    order_path         ,        --委托库路径
    order_confirm_path  ,        --委托确认库路径
    withdraw_path       ,        --委托撤单库路径
    withdraw_back_path  ,        --撤单回报库路径
    rights_path         ,        --权益库路径
    trusteeship_path    ,        --托管库路径
    trans_trust_path    ,        --转托管确认库路径
    comparison_path    ,        --对帐库路径
    sz_pg_path          ,        --配股确认库路径
    sh_g4_path          ,        --上海g4库路径
    sh_g5_path         ,        --上海g5库路径
    sh_g9_path         ,        --上海g9库路径
    sh_g7_path          ,        --上海g7库路径
    sh_g8_path         ,        --上海g8库路径
    sz_hm_path         ,        --深圳hm库路径
}

  finally
    ini.Free;
  end;
end;

function IsUseFile(sFileName : string ) : boolean;
var
  mFile : HFILE;
begin
  Result := false;
  if not FileExists(sFileName) then
    exit;
  mFile := CreateFile(pchar(sFileName), GENERIC_READ or GENERIC_WRITE,0, nil, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, 0);
  Result := (mFile = INVALID_HANDLE_VALUE);
  if not Result then
    CloseHandle(mFile);
end;

procedure TForm1.N5Click(Sender: TObject);
begin
  form2.ShowModal;
end;

procedure TForm1.N2Click(Sender: TObject);
var
  sFileName: string;
  sPathName: string;
begin
  CopyFile(sPathName,sFileName);
end;

procedure TForm1.Image2Click(Sender: TObject);
begin
  Application.Minimize;
end;

procedure TForm1.Image3Click(Sender: TObject);
begin
  Application.Terminate;
end;

procedure TForm1.fcOutlookBar1Enter(Sender: TObject);
begin
  fcOutlookBar1fcShapeBtn1.Font.Color := clBlue;
end;

procedure TForm1.fcOutlookBar1Exit(Sender: TObject);
begin
  fcOutlookBar1fcShapeBtn1.Font.Color := clRed;
end;

procedure TForm1.FileExitItemClick(Sender: TObject);
begin
  Application.Terminate;
end;

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  ReleaseCapture;
  Perform(WM_SYSCOMMAND, SC_MOVE or 1, 0);
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  NewMenuItem: TMenuItem;
  fIniFile: TIniFile;
  a : string;
begin
  CreateIniFile;

  NewMenuItem := TMenuItem.Create(self);

  if FileExists(ExtractFilePath(paramstr(0))+'RZCL.ini') then
  begin
    fIniFile := TIniFile.Create(ExtractFilePath(paramstr(0))+'RZCL.ini');
    NewMenuItem.Caption := fIniFile.ReadString('ReceiveFileLists','stair','');
    MainMenu1.Items[0].Items[0].Add(NewMenuItem);
  end;
  fIniFile.Free;
end;
以上是我的部分原代码。
我有一个主菜单,数据处理,然后下面有文件上传及文件下载两个子菜单,在FormCreate事件中我要根据我的INI 文件生成上传和下载文件清单的子菜单,

#12


可能应该是:
MainMenu1.Items[0].Add(NewMenuItem);
或许,你应该在
MainMenu1.Items[0]的OnClick事件中添加根据INI文件生成的子菜单,不要在FormCreate中生成

#13


在MainMenu1.Items[0]的OnClick事件中添加根据INI文件生成的子菜单就会每次点击时都会发生这个事件,好象不太好吧。