var
  MyStrList: TStringList; 
begin
  MyStrList:=TStringList.Create;
  MyStrList.Duplicates := dupIgnore;    //这一句
  MyStrList.Sorted := true;              //和这一句
end;
如果用了上面那两条语句,下面的改名就不行了,程序出错,如果要用下面的,上面的就不能用,怎么才能上下两个部分都可以用呢?
for i := 0 to myStrList.Count - 1 do
MyStrList[i] := ChangeFileExt(MyStrList[i],'(A).exe');

解决方案 »

  1.   

    我的代码不是在赋值前,加了这么一行代码吗?
    MyStrList.Sorted := false;
      

  2.   

    如果MyStrList中确有重复项下面代码当然不行。
    for i := 0 to myStrList.Count - 1 do
    MyStrList[i] := ChangeFileExt(MyStrList[i],'(A).exe');
    因为如果有重复项,MyStrList.Duplicates := dupIgnore设置将导致忽略,会使myStrList.Count减少,最终使循环次数超出实际的myStrList.Count 
    解决办法:1。for i:=mystrList.count-1 downto 0 
    2.for i := 0 to myStrList.Count - 1 do
    MyStrList[i] := ChangeFileExt(MyStrList[i],'(A).exe');
    MyStrList.Duplicates := dupIgnore;    
    >>上述代码在网吧编的,未经调试,你试试?
      

  3.   

    你赋值完了,在把sorted改为True啊,这么简单。
    MyStrList.Sorted := True;
    另外,我最后一次贴的代码确实加了,你没有注意罢了。