不知道哪里有问题啊 高手们帮忙看下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.
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.
解决方案 »
- 请教:如何在delphi中实现点对点的文件传输
- 涉外企业所得税申报系统中类似EXcel是用什么控件做的啊。DBGrid能实现吗
- 大家帮帮忙呀,关于动态生成控件问题!!!
- 关于工作中的自我评价
- 我想做一个按钮,将dbgrid中的数据另存为execl中,请问代码该怎么写呢?谢谢!
- 怎么把Double类型转换为时间类型,顶者有分
- 弱智问题,Tcombobox如何取得当前选中的text?
- ADO 的数据更新问题
- 救命呀!
- 一个简单问题:我的程序正在长时间的装载数据,在运行中我怎样接受用户的键盘消息,当用户按ESC时我弹出是否终止LOADING的对话框!
- 类重载和使用
- 如何获得ExecSQL的返回值,并显示给memo?不光执行select语句,还有执行其他的存储过程,比如xp_cmdshell。
FSearchRec对象是不是不存在啊?
s没有创建,访问时为空
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.
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.自己测试
FormCreate事件里面写:
s := TStringList.Create;FormDestroy事件里写:
s.Free;