if   OpenDialog.Execute   then
     // OpenDialog.FileName:='C:\test.txt';  //默认赋予一文件路径
      with   OpenDialog.Files   do
      for I:=0 to Count-1 do
      begin
          AssignFile(F,   Strings[I]);
          Reset(F);
          while not Eof(F) do
          begin
            Readln(F, FirstLine);
             ListBox1.Items.Add(FirstLine);
           end;
          CloseFile(F);
      end;     if   OpenDialog.Execute   then 每次读取默认的文件.不希望人工去选择.请问该这么做?

解决方案 »

  1.   

    不是应该设置opendialog的initialdir吗
      

  2.   

    >>每次读取默认的文件.不希望人工去选择.请问该这么做? 那就根本都不需要OpenDialog定义一个常量
    Const csFileName = 'C:\test.txt ';begin                    AssignFile(F,       csFileName); 
                        Reset(F); 
                        while   not   Eof(F)   do 
                        begin 
                            Readln(F,   FirstLine); 
                              ListBox1.Items.Add(FirstLine); 
                          end; 
                        CloseFile(F); end;
    你上边的代码,OpenDialog.Files 是指在对话框中,可以选择多个文件,然后来个for循环处理,
    如果这样的话,那就需要定义多个默认的字符串
      

  3.   

    如果是默认的路径就设置Initialdir,如果是默认的文件就用楼上的定义常量,或赋值。
      

  4.   

    既然不想人工参与,又何必使用OpenDialog呢?这个控件的用意就是需要人工的参与的呀。