各位大侠:
我在编程时:
(var commamd:string)
var str:Tstringlist;
command:='command.com /c nbtstat -a '+nmtime1.LocalIP+' >d:\temp.txt';
winexec(pchar(command),sw_hide);
str.LoadFromFile('d:\temp.txt');
       但,str.loadfromfile('d:\temp.txt') 总是大打不开 temp.txt 
出错提示:cannot open file temp.txt,但,temp.txt 存在呀!并可双击打开!
       请于解决!!

解决方案 »

  1.   

    var str:Tstringlist;
    command:='command.com /c nbtstat -a '+nmtime1.LocalIP+' >d:\temp.txt';
    winexec(pchar(command),sw_hide);
    str := TStringList.Create;
    str.LoadFromFile('d:\temp.txt');
    str.Free;
      

  2.   

    这是因为 winexec(pchar(command),sw_hide); 执行后
    马上就执行了 str.LoadFromFile('d:\temp.txt');
    这时temp.txt还没创建呢,当然打不开,可以这样:
    str := TStringList.Create;
    command:='command.com /c nbtstat -a 192.101.104.176 >d:\temp1.txt';
    winexec(pchar(command),sw_hide);
    // 等待文件生成
    while not FileExists('d:\temp1.txt') do Application.ProcessMessages;
    // 延时1秒(多少时间自己掌握)
    Sleep(1000);
    str.Lines.LoadFromFile('d:\temp1.txt');
      

  3.   

    小误,上面最后一句:str.LoadFromFile('d:\temp1.txt');
      

  4.   

    var str:Tstringlist;
    command:='command.com /c nbtstat -a '+nmtime1.LocalIP+' >d:\temp.txt';
    winexec(pchar(command),sw_hide);
    str.LoadFromFile('d:\temp.txt');
           
    问题是你没有创建STR的实例但你虽然声明了。str:=tstringlist.create;
    祝:
    身体健康
    答案和分数同样重要!!
      

  5.   

    学习. 我的程序中也用到了TStringList来保存和读取文件, 在两个模块中传递一些参数. 也没用到
    while not FileExists('d:\temp1.txt') do Application.ProcessMessages; Sleep(1000);
    但还没出错过.有点意义.