unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormShow(Sender: TObject);
var
SearchRec: TSearchRec;
nResult: Integer;
const
szFilePath =Application.EXEName+'\*.txt';
begin
//填充ListBox
ListBox1.Items.clear;
nResult:=FindFirst(szFilePath,faAnyFile,SearchRec); //查找第一个文件
while nResult = 0 do //如果返回值为0表示找到文件
begin
//将找到的文件添加到ListBox中;ExtractFilepath函数用于提取文件路径
ListBox1.Items.Add(Copy(SearchRec.Name,1,Length(SearchRec.Name)-POS('.',SearchRec.Name)+1));
nResult:=FindNext(SearchRec); //继续查找下一个文件,至到返回值不为0时
end;
end;end.

解决方案 »

  1.   

    你的问题是找不到*.txt吧.你ShowMessage(szFilePath)看看就知道了
     去掉Project后的.Exe就行了
      

  2.   

    再补充一下listBox1.items.add(Copy(SearchRec.Name,1,POS('.',SearchRec.Name)-1))
      

  3.   

    to NewPrince(Mack狼) "去掉Project后的.Exe就行了"请问:Project后的.exe是哪一行程序啊?
      

  4.   

    Var  Strdir,db :String;
      StrDir:=GetCurrentDir;
      db:=StrDir+'\*.ini';
      

  5.   

    sorry,應該是
    db:=StrDir+'\*.txt';
      

  6.   

    這句有問題:
    const
    szFilePath =Application.EXEName+'\*.txt';修改:
    szFilePath :=ExtractFileDir(Application.EXEName)+'\*.txt';
      

  7.   

    procedure TForm1.FormShow(Sender: TObject);
    var
    SearchRec: TSearchRec;
    s:string;
    nResult: Integer;
    //const
    //szFilePath =ExtractFilePath(Application.ExeName));begin
    //填充ListBox
    s:=ExtractFilePath(Application.ExeName)+'\*.txt';
    ListBox1.Items.clear;
    nResult:=FindFirst(s,faAnyFile,SearchRec); //查找第一个文件
    while nResult = 0 do //如果返回值为0表示找到文件
    begin
    //将找到的文件添加到ListBox中;ExtractFilepath函数用于提取文件路径
    ListBox1.Items.Add(Copy(SearchRec.Name,1,Length(SearchRec.Name)-4));
    nResult:=FindNext(SearchRec); //继续查找下一个文件,至到返回值不为0时
    end;
    end;