不知道哪里有问题啊 高手们帮忙看下unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure FindFile(APath: String;FList: TStrings);
    function GetDirectoryName(Dir: String): String;
    function IsDirNotation(ADirName: String): Boolean;
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;
  s:Tstrings;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
  findfile('d:\haha\',s);
end;procedure tform1.FindFile(APath: String;FList: TStrings);
var
FSearchRec,DSearchRec: TSearchRec;
FindResult: integer;
begin
    APath:=getdirectoryname(APath);
    FindResult := FindFirst(APath + '*.*',Faanyfile-faDirectory,FSearchRec);
    try
      while FindResult = 0 do
      begin
        FList.Add(APath+FSearchRec.name);
        FindResult := FindNext(FSearchRec);
      end;      FindResult := FindFirst(APath + '*.*',faDirectory,DSearchRec);      while FindResult = 0 do
      begin
        if ((DSearchRec.Attr and faDirectory) = faDirectory) and (not isDirNotation(DSearchRec.Name)) then
          FindFile(APath + DSearchRec.Name, FList);
        FindResult  := FindNext(DSearchRec);
      end;
    finally
      FindClose(FSearchRec);
      memo1.lines:=FList;
    end;
end;function Tform1.GetDirectoryName(Dir: String): String;
begin
if Dir[Length(Dir)] <> '\' then
    Result := Dir + '\'
else
    Result := Dir;
end;function tform1.IsDirNotation(ADirName: String): Boolean;
begin
Result := (ADirName = '.') or (ADirName = '..');
end;end.

解决方案 »

  1.   

    错误提示在这一行FList.Add(APath+FSearchRec.name);
      

  2.   

    FSearchRec.name 中,
    FSearchRec对象是不是不存在啊? 
      

  3.   

    findfile('d:\haha\',s);你的S在那里初始化的  
      

  4.   

    findfile('d:\haha\',s);你的S在那里初始化的  
      

  5.   

    findfile('d:\haha\',s);你的S在那里初始化的  
      

  6.   

    findfile('d:\haha\',s);
    s没有创建,访问时为空
      

  7.   


    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Edit1: TEdit;
        Button1: TButton;
        Memo1: TMemo;
        procedure Button1Click(Sender: TObject);
        procedure FindFile(APath: String;FList: TStrings);
        function GetDirectoryName(Dir: String): String;
        function IsDirNotation(ADirName: String): Boolean;
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      s:Tstrings;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
      S := TStringlist.create;
      findfile('d:\haha\',s);
    end;procedure tform1.FindFile(APath: String;FList: TStrings);
    var
    FSearchRec,DSearchRec: TSearchRec;
    FindResult: integer;
    begin
        APath:=getdirectoryname(APath);
        FindResult := FindFirst(APath + '*.*',Faanyfile-faDirectory,FSearchRec);
        try
          while FindResult = 0 do
          begin
            FList.Add(APath+FSearchRec.name);
            FindResult := FindNext(FSearchRec);
          end;      FindResult := FindFirst(APath + '*.*',faDirectory,DSearchRec);      while FindResult = 0 do
          begin
            if ((DSearchRec.Attr and faDirectory) = faDirectory) and (not isDirNotation(DSearchRec.Name)) then
              FindFile(APath + DSearchRec.Name, FList);
            FindResult  := FindNext(DSearchRec);
          end;
        finally
          FindClose(FSearchRec);
          memo1.lines:=FList;
        end;
    end;function Tform1.GetDirectoryName(Dir: String): String;
    begin
    if Dir[Length(Dir)] <> '\' then
        Result := Dir + '\'
    else
        Result := Dir;
    end;function tform1.IsDirNotation(ADirName: String): Boolean;
    begin
    Result := (ADirName = '.') or (ADirName = '..');
    end;end.
      

  8.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Edit1: TEdit;
        Button1: TButton;
        Memo1: TMemo;
        procedure Button1Click(Sender: TObject);
        procedure FindFile(APath: String);
        function GetDirectoryName(Dir: String): String;
        function IsDirNotation(ADirName: String): Boolean;
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
      memo1.clear;
      findfile('d:\haha\');
    end;procedure tform1.FindFile(APath: String);
    var
    FSearchRec,DSearchRec: TSearchRec;
    FindResult: integer;
    begin
        APath:=getdirectoryname(APath);
        FindResult := FindFirst(APath + '*.*',Faanyfile-faDirectory,FSearchRec);
        try
          while FindResult = 0 do
          begin
            memo1.lines.Add(APath+FSearchRec.name);
            FindResult := FindNext(FSearchRec);
          end;      FindResult := FindFirst(APath + '*.*',faDirectory,DSearchRec);      while FindResult = 0 do
          begin
            if ((DSearchRec.Attr and faDirectory) = faDirectory) and (not isDirNotation(DSearchRec.Name)) then
              FindFile(APath + DSearchRec.Name);
            FindResult  := FindNext(DSearchRec);
          end;
        finally
          FindClose(FSearchRec);
        end;
    end;function Tform1.GetDirectoryName(Dir: String): String;
    begin
    if Dir[Length(Dir)] <> '\' then
        Result := Dir + '\'
    else
        Result := Dir;
    end;function tform1.IsDirNotation(ADirName: String): Boolean;
    begin
    Result := (ADirName = '.') or (ADirName = '..');
    end;end.自己测试 
      

  9.   

    可以想象,你的AV错误代码,地址肯定是全0的。因为你这个S:TStrings没有创建实例就在使用。
    FormCreate事件里面写:
    s := TStringList.Create;FormDestroy事件里写:
    s.Free;