在那一句出错?for i:=1 to k-1 do
begin
  check:=TStringList.Create;
  check:=filecheck(dir[i]);
  check.Free;               //不是很明白,check起什么作用?
end;

解决方案 »

  1.   

    大哥是
      在 check:=filecheck(dir[i]);
    后查看变量check.strings[0]出现
    check.strings[0]: Delphi exception EStringListError at $655F981
    我是用来测试的
    看filecheck函数的返回值能不能符值过来?
    请指教?
      

  2.   

    function filecheck(filename:string):TstringList;错误在mfile.free;//不能释放,否则result值被清掉你最好不要在该函数中定义mfile,因为它不能在该函数体内释放。
      

  3.   

    result:=mfile;
    mfile.free;你都把这个StringList free掉了,也就是说filecheck返回的只是个无效的指针
    当然要出错拉
    你不应该在filecheck这个函数体中把mfile free掉
      

  4.   

    那怎么办呀?
    不释放的话
    不停的create,就会内存不够
    用clear好像也不行?
    请帮我想想办法?
    谢谢!
      

  5.   

    你可以将mfile定义在函数外,一次create,在函数中使用前clear;
      

  6.   

    check:=TStringList.Create;
      check:=filecheck(dir[i]);
      check.Free;试试把check:=TStringList.Create去掉;
    check.Free 换成filecheck.free
    考虑到check在这里只是作为一个指针,所以
    check:=nil;应该就没问题了
      

  7.   

    check:=filecheck(dir[i]);
      check.Free;
    错误!
    现在的Check没有指向对象!因为在函数体内已释放了!
      

  8.   

    大哥,mfile定义在函数体外?
    在那定义呀?var form1:Tform后面?
    还有mfile:=TStringList.create;
    写在哪里?
      

  9.   

    我把mfile:=TstringList.create;把mfile定义在form1:TForm之后
    但它只能运行三个文件,到第四个时出现file not found
    为什么?相关代码见上面!