即上一步生成文件有个时间延时,接着我想打开文件时,如果文件还未创建,则不断重复此操作,直至正常打开为止。该如何做呢?

解决方案 »

  1.   

    repeat
    ...
    until (FileOpen(MyFile, fmOpen) <> -1)
      

  2.   

    Sleep一段时间后在打开!!!或是做一个空循环延时.
      

  3.   

    repeat
    ...
    until (FileOpen(MyFile, fmOpen) <> -1)絕對ok,我用過
      

  4.   

    filestr:= 'li'+DateToStr(Date())+'.txt';
      str:='cmd /c dir > '+filestr;
      WinExec(pchar(Str),sw_hide);
      tmpi := 0;
      repeat
        sleep(1000);
        inc(tmpi);
      until (Fileexists(filestr) or (tmpi>100)); //不能无限循环
      assignfile(dataFile,filestr);
      try
        reset(dataFile);
        memo1.Lines.LoadFromFile(filestr);
      except
        showmessage('配置文件错误!'+filestr);
        Application.Terminate;
      end;
      closefile(dataFile);
    用了以上代码,基本解决,但将编译好的文件作为系统自启动程序运行时,还是报错'配置文件错误!',但系统启动完毕直接运行,则是好的,痛苦...
      

  5.   

    repeat
    ...
    until (FileOpen(MyFile, fmOpen) <> -1)
    肯定可以的