procedure TForm1.LanguageEnglishClick(Sender: TObject);
const
  MENU_TAG1='1' ; //测试菜单在ini中的编号
  MENU_TAG2='2'; //设置的菜单在ini中的编号
  MENU_TAG3='3'; // 帮助的
  MENU_TAG4='4';  //语言的
var
   Component: TComponent;
   i,j:integer;
   IniFileName:string;
   MyIniFile:Tinifile;  //ini文件名
begin
  IniFilename:=ExtractFilePath(Paramstr(0))+'English.ini';
  MyIniFile:=Tinifile.Create(IniFileName);
for j:=0 to Screen.Forms[0].ComponentCount - 1 do
    begin
       Component := Screen.Forms[0].Components[j] as TComponent;
       if component is TmenuItem then
          begin
             if (TMenuItem(Component).Caption<>'') and (TMenuItem(Component).Caption <>'-') then
                 TMenuItem(Component).Caption := MyIniFile.ReadString('Menu','1'+ inttostr(j-1), TMenuItem(Component).Caption);
          end;
    end;
end;

解决方案 »

  1.   

    就是程序可以执行,但是希望原来的菜单,比如“文件”中的‘打开’,变成open(依此类推)。 MyIniFile就是读取ini文件来英化界面。
    但是好像一点反应也没有,不知道作在那里,请指教。
      

  2.   


     if component is TmenuItem then
    改成
     if component.ClassName= 'TmenuItem' then
    行不行呢
      

  3.   

    to NightCloud() 
    试过了,好像不行:(
      

  4.   

    我知道错在哪里了!
    IniFilename:=ExtractFilePath(Paramstr(0))+'English.ini';
    以上语句有错!
    你可以写成这样:
    IniFilename:=StringReplae(ExtractFilePath(Application.ExeName)+'\English.ini','\\','\',[rfReplaceAll]);你的文件名肯定没有取到呢!呵呵,我也犯过这样的错呢!
      

  5.   

    不好意思,上面应该是StringReplace函数,写错了!
      

  6.   

    to  yczyk(小周)
    试过了,也不行啊!:(
      

  7.   

    试试 if Screen.Forms[0].Components[j].ClassName='TMENUITEM' then
      

  8.   

    to NightCloud() 
      这个方法是过了,没有用啊!:(
      

  9.   

    测试过,程序没有问题
    我你的问题可能是:
    1。在下面的读取字符串时
    TMenuItem(Component).Caption := MyIniFile.ReadString('Menu','1'+ inttostr(j-1), TMenuItem(Component).Caption);
    '1'+ inttostr(j-1) 应该是 11,12,13,(你的意思是inttostr(j)?)
     在ini的格式应该是
     [menu]
     11 = open
     12 = close
     不是
     [menu]
     1= open
     2=closeMENU_TAG好像没有用?~~
      

  10.   

    不好意思,写错了
    试试 if Screen.Forms[0].Components[j].ClassNameis('TMENUITEM') then
    这个应该是可以的。再不行就有可能是如 laihecongxi(兴哥) 所说的了
    或者你单步调试一下if .. then语句后面的语句有没有被执行,把错误定位得更准确点
      

  11.   

    if (TMenuItem(Component).Caption<>'') and (TMenuItem(Component).Caption <>'-') then
                     TMenuItem(Component).Caption := MyIniFile.ReadString('Menu','1'+ inttostr(j-1), TMenuItem(Component).Caption);
              end;应该是这一行的问题。
      

  12.   

    这里面if条件也进去了,就不知道为什么没有反应?to  hydonlee(青山情) 
    错在那里那??
      

  13.   

    to laihecongxi(兴哥) 我的ini的格式是
     [menu]
     10 = open
     11 = close  .........
    所以我用j-1,menu_tag1是表示文件菜单,而menu_tag2是表示编辑菜单........
      

  14.   

    show一下这个值:
    MyIniFile.ReadString('Menu','1'+ inttostr(j-1), TMenuItem(Component).Caption);
    看有没有取出来
      

  15.   


    如果按你源代码,如果又其他组件的话j的值不是你想像的0,1,2...
    所以下面这句要改一下。利用Tag值在判断一下
    ......
    with TMenuItem(Component) do
         Caption := 
         MyIniFile.ReadString('Menu','1'+ inttostr(tag-1),Caption);{设置菜单item的Tag值为MENU_TAG,}
      

  16.   

    应该ok了吧?
    我想你的i是为循环Screen.form[i]预留的吧,测试过了全体窗体可以实现的。
      

  17.   

    正确了,to laihecongxi(兴哥)
    thank u very much