控件为listbox1,listbox2和memo1产品引入.txt文本内容为产品名称          资料目录                                  资料文件名称本机服务材料      D:\1\                                     *.txt 
网络服务材料      L:\2\                                     *.*  
现有图表资料      D:\3\图表\                                *.jpg  
其他              d:                                        *.*(需要在listbox1中添加产品名称内容《本机服务材料,网络服务材料,现有图表资料,其他》,点击listbox1中的项,listbox2出现该项所对应的目录内符合条件的文件,点击文件,在memo1中显示文件内容谢谢大家了

解决方案 »

  1.   

    在更改产品引入.txt中的内容时,listbox中的内容也相应改变
    产品引入.txt为配置文件
      

  2.   

    ListBox1.Items.Add()添加产品目录,onclick事件添加ListBox2的内容,再写好ListBox2的onclick事件,读取文本就定义一个TextFile,ReadLn就差不多了
      

  3.   

    你的文本文件必须有固定的格式或规律才能啊,比如说产品名称、资料目录和资料文件名称之间都有空格
    先逐行读取文本文件
    var
      f:TextFile;
      str:string;
    begin
      assignfile(f,path+'产品引入.txt');
      reset(f);
      repeat
        readln(f,str);
        //这里是内容分析,第一个非连续空格前为产品名称,第二个非连续空格前为资料目录,后面的内容就是资料文件名称
        //先把这些信息按照顺序存放到数组或listbox里,只是把产品名臣显示到界面的listbox1中
      until
        seekeof(f);
      closefile(f);
    end;
    listbox1的onclick事件中
    i:=self.listbox1.itemindex;
    通过i再到事件存放信息的数组或listbox中读取其资料目录和资料文件名称的内容
      

  4.   

    如果采用配置文件的格式,是不是会更好处理一些,比如文件格式如下
    [产品名称]
    cou=4
    cp1=本机服务材料
    cp2=网络服务材料、
    cp3=现有图书资料
    cp4=其它
    [资料目录]
    cp1=D:\1\ 
    cp2=L:\2\  
    cp3=D:\3\图表\ 
    cp4=D:
    [资料文件名称]
    cp1=*.txt
    cp2=*.*
    cp3=*.jpg
    cp4=*.*
      

  5.   

    如果需要把所有文件都列出来,那还需要对资料目录进行搜索,给你一段代码,这是我写的文件搜索代码,应该可以用procedure TForm1.findfile(path,filename: string);
    var
      sr:TSearchrec;
      i,j:integer;
      localtime:TFileTime;
      systime:TSystemTime;
      dt:TDateTime;
      si:real;
      s,typ,s1:string;
      name1,name2:string;
    begin
      if findfirst(path+'*.*',faanyfile,sr)=0 then
      begin
        repeat
          if (sr.Attr and fadirectory=fadirectory) and (sr.Name<>'.') and (sr.Name<>'..') then
          begin
            form1.StatusBar1.SimpleText:='正在搜索:'+path+sr.Name;
            application.ProcessMessages;
            if form1.CheckBox1.Checked=false then
            begin
              name1:=uppercase(filename);
              name2:=uppercase(sr.Name);
            end
            else
            begin
              name1:=filename;
              name2:=sr.Name;
            end;
            if form1.isfile_searched(name1,name2) then
            begin
              form1.vg_count:=form1.vg_count+1;
              if form1.vg_count>form1.StringGrid1.RowCount-1 then
                form1.StringGrid1.RowCount:=form1.StringGrid1.RowCount+1;
              i:=form1.vg_count;
              form1.StringGrid1.Cells[0,i]:=sr.Name;
              form1.StringGrid1.Cells[1,i]:=path;
              si:=sr.Size/1024;
              j:=pos('.',floattostr(si));
              s:=format('%'+inttostr(j-1)+'.1f',[si]);
              form1.StringGrid1.Cells[2,i]:=s+'KB';
              dt:=filedatetodatetime(sr.Time);
              form1.StringGrid1.Cells[3,i]:=datetimetostr(dt);
            end;
            form1.findfile(path+sr.Name+'\',filename);
          end;
        until
          findnext(sr)<>0;
        findclose(sr);
      end;
      if findfirst(path+'*.*',faanyfile,sr)=0 then
      //if findfirst(path+'*'+filename+'*',faanyfile,sr)=0 then
      begin
        repeat
          if form1.CheckBox1.Checked=false then
          begin
            name1:=uppercase(filename);
            name2:=uppercase(sr.Name);
          end
          else
          begin
            name1:=filename;
            name2:=sr.Name;
          end;
          if form1.isfile_searched(name1,name2) then
          begin
            form1.vg_count:=form1.vg_count+1;
            if form1.vg_count>form1.StringGrid1.RowCount-1 then
              form1.StringGrid1.RowCount:=form1.StringGrid1.RowCount+1;
            i:=form1.vg_count;
            form1.StringGrid1.Cells[0,i]:=sr.Name;
            form1.StringGrid1.Cells[1,i]:=path;
            si:=sr.Size/1024;
            j:=pos('.',floattostr(si));
            s:=format('%'+inttostr(j-1)+'.1f',[si]);
            form1.StringGrid1.Cells[2,i]:=s+'KB';
            dt:=filedatetodatetime(sr.Time);
            form1.StringGrid1.Cells[3,i]:=datetimetostr(dt);
          end;
        until
          findnext(sr)<>0;
        findclose(sr);
      end;
    end;比如说搜索本地服务资料 
    findfile('D:\1\','*.txt')
      

  6.   

    里面还有这个函数,代码如下function TForm1.isfile_searched(sfilename, rfilename: string): boolean;
    var
      i,j,m,n:integer;
      s,s1:string;
    begin
      result:=false;
      form1.vg_s1:='';
      form1.vg_s2:='';
      form1.vg_cou_why:=0;
      form1.vg_len:=0;
      if (pos('*',sfilename)>0) or (pos('?',sfilename)>0) then//含有通配符
      begin
        i:=length(sfilename);
        for j:=1 to i do
        begin
          if sfilename[j]='*' then
          begin
            form1.vg_flag_start:=true;
            if form1.vg_s2<>'' then
            begin
              if form1.vg_s1='' then
              begin
                if form1.vg_cou_why>0 then
                begin
                  if pos(form1.vg_s2,rfilename)+form1.vg_len=form1.vg_cou_why+1 then
                  begin
                    if j=i then
                    begin
                      result:=true;
                    end
                    else
                    begin
                      form1.vg_filename:=rfilename;
                      m:=pos(form1.vg_s2,rfilename);
                      n:=length(rfilename);
                      rfilename:=copy(rfilename,m+1,n-m);
                      form1.vg_len:=m;
                    end;
                  end
                  else
                  begin
                    result:=false;
                    exit;
                  end;
                end
                else
                begin
                  if pos(form1.vg_s2,rfilename)>0 then
                  begin
                    if j=i then
                      result:=true
                    else
                    begin
                      form1.vg_filename:=rfilename;
                      m:=pos(form1.vg_s2,rfilename);
                      n:=length(rfilename);
                      rfilename:=copy(rfilename,m+1,n-m);
                      form1.vg_len:=m;
                    end;
                  end
                  else
                  begin
                    result:=false;
                    exit;
                  end;
                end;
              end
              else
              begin
                if form1.vg_cou_why>0 then
                begin
                  if pos(form1.vg_s2,rfilename)+form1.vg_len-pos(form1.vg_s1,form1.vg_filename)-1=form1.vg_cou_why then
                  begin
                    if j=i then
                      result:=true
                    else
                    begin
                      form1.vg_filename:=rfilename;
                      m:=pos(form1.vg_s2,rfilename);
                      n:=length(rfilename);
                      rfilename:=copy(rfilename,m+1,n-m);
                      form1.vg_len:=m;
                    end;
                  end
                  else
                  begin
                    result:=false;
                    exit;
                  end;
                end
                else
                begin
                  if pos(form1.vg_s2,rfilename)>0 then
                  begin
                    if j=i then
                      result:=true
                    else
                    begin
                      form1.vg_filename:=rfilename;
                      m:=pos(form1.vg_s2,rfilename);
                      n:=length(rfilename);
                      rfilename:=copy(rfilename,m+1,n-m);
                      form1.vg_len:=m;
                    end;
                  end
                  else
                  begin
                    result:=false;
                    exit;
                  end;
                end;
              end;
              form1.vg_s1:=form1.vg_s2;
            end;
            form1.vg_cou_why:=0;
            form1.vg_s2:='';
          end
          else
          begin
            if sfilename[j]='?' then
            begin
              if form1.vg_s2<>'' then
              begin
                if form1.vg_s1='' then
                begin
                  if form1.vg_cou_why>0 then
                  begin
                    if pos(form1.vg_s2,rfilename)+form1.vg_len=form1.vg_cou_why+1 then
                    begin
                      if j=i then
                      begin
                        m:=pos(form1.vg_s2,rfilename);
                        n:=length(rfilename);
                        if m+1=n then
                          result:=true
                        else
                          result:=false;
                      end
                      else
                      begin
                        form1.vg_filename:=rfilename;
                        m:=pos(form1.vg_s2,rfilename);
                        n:=length(rfilename);
                        rfilename:=copy(rfilename,m+1,n-m);
                        form1.vg_len:=m;
                      end;
                    end
                    else
                    begin
                      result:=false;
                      exit;
                    end;
                  end
                  else
                  begin
                    if pos(form1.vg_s2,rfilename)>0 then
                    begin
                      if j=i then
                        result:=true
                      else
                      begin
                        form1.vg_filename:=rfilename;
                        m:=pos(form1.vg_s2,rfilename);
                        n:=length(rfilename);
                        rfilename:=copy(rfilename,m+1,n-m);
                        form1.vg_len:=m;
                      end;
                    end
                    else
                    begin
                      result:=false;
                      exit;
                    end;
                  end;
                end
                else
                begin
                  if form1.vg_cou_why>0 then
                  begin
                    if pos(form1.vg_s2,rfilename)+form1.vg_len-pos(form1.vg_s1,form1.vg_filename)-1=form1.vg_cou_why then
                    begin
                      if j=i then
                        result:=true
                      else
                      begin
                        form1.vg_filename:=rfilename;
                        m:=pos(form1.vg_s2,rfilename);
                        n:=length(rfilename);
                        rfilename:=copy(rfilename,m+1,n-m);
                        form1.vg_len:=m;
                      end;
                    end
                    else
                    begin
                      result:=false;
                      exit;
                    end;
                  end
                  else
                  begin
                    if pos(form1.vg_s2,rfilename)>0 then
                    begin
                      if j=i then
                        result:=true
                      else
                      begin
                        form1.vg_filename:=rfilename;
                        m:=pos(form1.vg_s2,rfilename);
                        n:=length(rfilename);
                        rfilename:=copy(rfilename,m+1,n-m);
                        form1.vg_len:=m;
                      end;
                    end
                    else
                    begin
                      result:=false;
                      exit;
                    end;
                  end;
                end;
                form1.vg_s1:=form1.vg_s2;
              end;
              form1.vg_s2:='';
              if j=1 then
                form1.vg_cou_why:=1
              else
              begin
                if form1.vg_flag_start=false then
                begin
                  if sfilename[j-1]='?' then
                    form1.vg_cou_why:=form1.vg_cou_why+1
                  else
                    form1.vg_cou_why:=1;
                end
                else
                  form1.vg_cou_why:=0;
              end;
            end
      

  7.   

    继续        else
            begin
              form1.vg_flag_start:=false;
              form1.vg_s2:=form1.vg_s2+sfilename[j];
              if j=i then
              begin
                if form1.vg_s1='' then
                begin
                  if form1.vg_cou_why>0 then
                  begin
                    if pos(form1.vg_s2,rfilename)+form1.vg_len=form1.vg_cou_why+1 then
                    begin
                      if j=i then
                      begin
                        result:=true;
                      end
                      else
                      begin
                        form1.vg_filename:=rfilename;
                        m:=pos(form1.vg_s2,rfilename);
                        n:=length(rfilename);
                        rfilename:=copy(rfilename,m+1,n-m);
                        form1.vg_len:=m;
                      end;
                    end
                    else
                    begin
                      result:=false;
                      exit;
                    end;
                  end
                  else
                  begin
                    if pos(form1.vg_s2,rfilename)>0 then
                    begin
                      if j=i then
                        result:=true
                      else
                      begin
                        form1.vg_filename:=rfilename;
                        m:=pos(form1.vg_s2,rfilename);
                        n:=length(rfilename);
                        rfilename:=copy(rfilename,m+1,n-m);
                        form1.vg_len:=m;
                      end;
                    end
                    else
                    begin
                      result:=false;
                      exit;
                    end;
                  end;
                end
                else
                begin
                  if form1.vg_cou_why>0 then
                  begin
                    if pos(form1.vg_s2,rfilename)+form1.vg_len-pos(form1.vg_s1,form1.vg_filename)-1=form1.vg_cou_why then
                    begin
                      if j=i then
                        result:=true
                      else
                      begin
                        form1.vg_filename:=rfilename;
                        m:=pos(form1.vg_s2,rfilename);
                        n:=length(rfilename);
                        rfilename:=copy(rfilename,m+1,n-m);
                        form1.vg_len:=m;
                      end;
                    end
                    else
                    begin
                      result:=false;
                      exit;
                    end;
                  end
                  else
                  begin
                    if pos(form1.vg_s2,rfilename)>0 then
                    begin
                      if j=i then
                        result:=true
                      else
                      begin
                        form1.vg_filename:=rfilename;
                        m:=pos(form1.vg_s2,rfilename);
                        n:=length(rfilename);
                        rfilename:=copy(rfilename,m+1,n-m);
                        form1.vg_len:=m;
                      end;
                    end
                    else
                    begin
                      result:=false;
                      exit;
                    end;
                  end;
                end;
              end;
            end;
          end;
        end;
      end
      else
      begin
        if pos(sfilename,rfilename)>0 then
          result:=true
        else
          result:=false;
      end;
    end;
      

  8.   

    对“产品引入.txt”文件有一定要求:各列内容定长,各列内容可以少于固定长度,但不能超出。你的文件是这样吗?
      

  9.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls, StdCtrls;type cpyr=Record
       cpmc:String;
       zlml:String;
    end;
    type cpyrs=array [1..4] of cpyr;type
      TForm1 = class(TForm)
        lst1: TListBox;
        lst2: TListBox;
        memo1: TMemo;
        btn1: TButton;
        img1: TImage;
        btn2: TButton;
        procedure btn1Click(Sender: TObject);
        procedure lst1Click(Sender: TObject);
        procedure lst2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        cp1,ml1:String;
        cp2,ml2:String;
        cp3,ml3:String;
        cp4,ml4:String;
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.btn1Click(Sender: TObject);//读取 txt文件
    var
      s1,s2:String;
      s3,s4,s5:String;
      st1,st2:TStringList;
      i:Integer;
    begin
      s1:=ExtractFilePath(Application.ExeName);
      s2:=s1+'1.txt';
      st1:=TStringList.Create;
      st1.LoadFromFile(s2);  st1.Delete(0);
      st1.Delete(0);  s3:=st1[0];
      cp1:=Trim(copy(s3,1,12));
      ml1:=Trim(copy(s3,13,22));  s3:=st1[1];
      cp2:=Trim(copy(s3,1,12));
      ml2:=Trim(copy(s3,13,22));  s3:=st1[2];
      cp3:=Trim(copy(s3,1,12));
      ml3:=Trim(copy(s3,13,22));  s3:=st1[3];
      cp4:=Trim(copy(s3,1,12));
      ml4:=Trim(copy(s3,13,22));  lst1.Clear;
      lst1.Items.Add(cp1);
      lst1.Items.Add(cp2);
      lst1.Items.Add(cp3);
      lst1.Items.Add(cp4);
    end;procedure TForm1.lst1Click(Sender: TObject);//点击lst1时更新lst2内容
      procedure ReadFileName(var MyFileList : TStringList; const AnyFile:String); 
      var
        Found:integer; 
        SearchResult:TSearchRec; 
      begin 
        if FileGetAttr(AnyFile)<>faDirectory then begin
          MyFileList.Add(AnyFile);      Exit; 
        end; 
        Found:=FindFirst(AnyFile+'*.*',faAnyFile,SearchResult); 
        while Found=0 do begin 
          if (SearchResult.Name<>'.')and(SearchResult.Name<>'..') then ReadFileName(MyFileList,AnyFile+SearchResult.Name);
          Found:=FindNext(SearchResult); 
        end;
        if (SearchResult.Name<>'.')and(SearchResult.Name<>'..') then FindClose(SearchResult);
      end;
    var
     st1:TStringList;
     s1:String;begin
      st1:=TStringList.Create;
      if lst1.ItemIndex=0 then
      begin
        ReadFileName(st1,ml1);
      end;
      if lst1.ItemIndex=1 then
      begin
        ReadFileName(st1,ml2);
      end;
      if lst1.ItemIndex=2 then
      begin
        ReadFileName(st1,ml3);
      end;
      if lst1.ItemIndex=3 then
      begin
        ReadFileName(st1,ml4);
      end;
      lst2.Clear;
      lst2.Items.Assign(st1);
    end;procedure TForm1.lst2Click(Sender: TObject);//点击lst2时memo显示选择文件的内容
    var
      s1:String;
    begin
      s1:=lst2.Items[lst2.ItemIndex];
      memo1.Clear;
      memo1.Lines.LoadFromFile(s1);
    end;end.
      

  10.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls, StdCtrls;type
      TForm1 = class(TForm)
        lst1: TListBox;
        lst2: TListBox;
        memo1: TMemo;
        btn1: TButton;
        img1: TImage;
        btn2: TButton;
        procedure btn1Click(Sender: TObject);
        procedure lst1Click(Sender: TObject);
        procedure lst2Click(Sender: TObject);
        procedure FormShow(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        cp1,ml1:String;//记录第1行  产品名称  资料目录
        cp2,ml2:String;//记录第2行  产品名称  资料目录
        cp3,ml3:String;//记录第3行  产品名称  资料目录
        cp4,ml4:String;//记录第4行  产品名称  资料目录
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormShow(Sender: TObject);//读取 txt文件  填充lst1
    var
      s1,s2:String;
      s3,s4,s5:String;
      st1,st2:TStringList;
      i:Integer;
    begin
      s1:=ExtractFilePath(Application.ExeName);
      s2:=s1+'1.txt';
      st1:=TStringList.Create;
      st1.LoadFromFile(s2);  st1.Delete(0);
      st1.Delete(0);  s3:=st1[0];
      cp1:=Trim(copy(s3,1,12));
      ml1:=Trim(copy(s3,13,22));  s3:=st1[1];
      cp2:=Trim(copy(s3,1,12));
      ml2:=Trim(copy(s3,13,22));  s3:=st1[2];
      cp3:=Trim(copy(s3,1,12));
      ml3:=Trim(copy(s3,13,22));  s3:=st1[3];
      cp4:=Trim(copy(s3,1,12));
      ml4:=Trim(copy(s3,13,22));  lst1.Clear;
      lst1.Items.Add(cp1);
      lst1.Items.Add(cp2);
      lst1.Items.Add(cp3);
      lst1.Items.Add(cp4);
    end;procedure TForm1.lst1Click(Sender: TObject);//点击lst1时更新lst2内容  procedure ReadFileName(var MyFileList : TStringList; const AnyFile:String);//枚举目录包含的文件
      var
        Found:integer;
        SearchResult:TSearchRec;
      begin
        if FileGetAttr(AnyFile)<>faDirectory then begin
          MyFileList.Add(AnyFile);      Exit;
        end;
        Found:=FindFirst(AnyFile+'*.*',faAnyFile,SearchResult);
        while Found=0 do begin
          if (SearchResult.Name<>'.')and(SearchResult.Name<>'..') then ReadFileName(MyFileList,AnyFile+SearchResult.Name);
          Found:=FindNext(SearchResult);
        end;
        if (SearchResult.Name<>'.')and(SearchResult.Name<>'..') then FindClose(SearchResult);
      end;var
     st1:TStringList;
     s1:String;
    begin
      st1:=TStringList.Create;
      if lst1.ItemIndex=0 then
      begin
        ReadFileName(st1,ml1);
      end;
      if lst1.ItemIndex=1 then
      begin
        ReadFileName(st1,ml2);
      end;
      if lst1.ItemIndex=2 then
      begin
        ReadFileName(st1,ml3);
      end;
      if lst1.ItemIndex=3 then
      begin
        ReadFileName(st1,ml4);
      end;
      lst2.Clear;
      lst2.Items.Assign(st1);
    end;procedure TForm1.lst2Click(Sender: TObject);//点击lst2时memo显示选择文件的内容
    var
      s1:String;
    begin
      s1:=lst2.Items[lst2.ItemIndex];
      memo1.Clear;
      memo1.Lines.LoadFromFile(s1);
    end;
    end.
      

  11.   

    ...
    var
      Form1: TForm1;implementation{$R *.dfm}type
      PDataNode=^TDataNode;
      TDataNode=record
        Name:string;//产品名称
        Dir:string;//资料目录
        Ext:string;//扩展名
    end;procedure SearchFile(APath,AExt:string;AStrings:TStrings);
    var
      SR:TSearchRec;
    begin
      if APath[length(APath)]<>'\' then APath:=APath+'\';  if (FindFirst(APath+'*.*',faAnyFile,SR)=0) then
      begin
        repeat
          if (SR.Name='.') or (SR.Name='..') then Continue;      if (sr.Attr and faDirectory<>0) or
             (sr.Attr and faArchive<>0) then
            SearchFile(APath+SR.Name,AExt,AStrings);      if UpperCase(('*'+ExtractFileExt(sr.Name)))=AExt then
            AStrings.Add(APath+sr.Name);
        until FindNext(SR)<>0;
      end;
      
      FindClose(sr);
    end;procedure TForm1.FormCreate(Sender: TObject);
    var
      sList:TStringList;
      sLine:string;
      i,index:Integer;
      DataNode:PDataNode;
    begin
      sList:=TStringList.Create;
      try
        sList.LoadFromFile('产品引入.txt');
        for i:=1 to sList.Count-1 do  //忽略第一行
        begin
          sLine:=sList.Strings[i];
          if sLine<>'' then
          begin
            New(DataNode);
            index:=Pos(' ',sLine);
            DataNode^.Name:=Copy(sLine,1,index-1);
            sLine:=trimLeft(Copy(sLine,index,length(sLine)));
            index:=Pos(' ',sLine);
            DataNode^.Dir:=Copy(sLine,1,index-1);
            DataNode^.Ext:=UpperCase(trim(Copy(sLine,index,length(sLine))));
            ListBox1.Items.AddObject(DataNode^.Name,TObject(DataNode));
          end;
        end;
      finally
        sList.Free;
      end;
    end;procedure TForm1.ListBox1Click(Sender: TObject);
    var
      index:Integer;
    begin
      index:=ListBox1.ItemIndex;
      if index=-1 then exit;  ListBox2.Items.Clear;  SearchFile(pDataNode(ListBox1.Items.Objects[index])^.Dir,
        pDataNode(ListBox1.Items.Objects[index])^.Ext,ListBox2.Items);
    end;procedure TForm1.ListBox2DblClick(Sender: TObject);
    begin
      Memo1.Lines.LoadFromFile(ListBox2.Items[ListBox2.ItemIndex]);
    end;procedure TForm1.FormDestroy(Sender: TObject);
    var
      p:Pointer;
    begin
      while ListBox1.Items.Count>0 do
      begin
        p:=ListBox1.Items.Objects[0];
        if Assigned(p) then Dispose(p);
        ListBox1.Items.Delete(0);
      end;
    end;
      

  12.   


    procedure TForm1.Button2Click(Sender: TObject);
    var
      fl:TINIfile;
      path,s:string;
      cou,j:Integer;
    begin
      path:=ExtractFilePath(application.ExeName);
      fl:=TIniFile.Create(path+'param.ini');
      cou:=fl.ReadInteger('产品名称','cou',0);
      if cou=0 then
        Exit;
      self.ListBox1.Items.Clear;
      for j:=1 to cou do
      begin
        s:=fl.ReadString('产品名称','cp'+inttostr(j),'');
        if s<>'' then
          Self.ListBox1.Items.Add(s);
      end;
      fl.Free;
    end;procedure TForm1.ListBox1Click(Sender: TObject);
    var
      i:Integer;
    var
      fl:TINIfile;
      path,s:string;
      cou,j:Integer;
    begin
      i:=self.ListBox1.ItemIndex;
      if i=-1 then
        Exit;
      self.ListBox2.Items.Clear;
      self.ListBox3.Items.Clear;
      path:=ExtractFilePath(application.ExeName);
      fl:=TIniFile.Create(path+'param.ini');
      s:=fl.ReadString('资料目录','cp'+inttostr(i+1),'');
      if s<>'' then
        self.ListBox2.Items.Add(s);
      s:=fl.ReadString('资料文件名称','cp'+inttostr(i+1),'');
      if s<>'' then
        self.ListBox3.Items.Add(s);
      fl.Free;
    end;
      

  13.   

    lovelymelon,你好,这个是将产品名称等加入到listbox中,我想请教下你假如点击listbox1,在listbox2中列出配置文件中相应文件夹下符合文件名称的文件,这个具体责呢吗实现?谢谢
      

  14.   

    前面我已经给过你遍历文件夹查询文件的代码了
    procedure TForm1.ListBox1Click(Sender: TObject);
    var
      i:Integer;
    var
      fl:TINIfile;
      path,s1,s2:string;
      cou,j:Integer;
    begin
      i:=self.ListBox1.ItemIndex;
      if i=-1 then
        Exit;
      self.ListBox2.Items.Clear;
      self.ListBox3.Items.Clear;
      path:=ExtractFilePath(application.ExeName);
      fl:=TIniFile.Create(path+'param.ini');
      s1:=fl.ReadString('资料目录','cp'+inttostr(i+1),'');
      if s1='' then
        exit;
      s2:=fl.ReadString('资料文件名称','cp'+inttostr(i+1),'');
      if s2='' then
        exit;
      fl.Free;
      find_file(s1,s2)//这个函数在前面已经给过你
    end;