我这有100分,谁帮帮写个线程进行目录文件遍历的程序(100分)

N

next

Unregistered / Unconfirmed
GUEST, unregistred user!
今天下午,想写个程序要用到文件遍历(比如遍历c盘下的所有文件),如果不用多线程的 
话很好写,但把同样的程序写到一个单独的线程里面就是没用,(出现的问题大致是
递归后不能有效的返回),唉,我都快疯了,郁闷了一个下午!!都怪自己学艺不精哪!
哪位仁兄能帮我写个利用线程遍历的程序,我谢谢谢谢谢!!!!! 
顺便问一下,Delphi中有没有像C一样的静态变量(static),在一个子过程中要用到
计数,但不想申明全程变量,要是有静态变量就好了,不过想来没有的,好多书上都没
提。(最近刚刚从c++Builder中转过来的,有点不适应,不过已经慢慢感受到了小D的优点
了,不过我是真菜啊, 请各位多多指教!!!)
 
delphi6 开发人员指南 中有 这个例子 完整的代码 完全符合 你的要求 也是多线程的
不过我手里 没有 光盘
不好意思
 
1. http://www.delphibbs.com/delphibbs/dispq.asp?lid=1720993
2.将变量声明写在implementation之后即可。
例如:
implementation
{$R *.DFM}
var
i: integer;
 
谢谢楼上两位,
to Yves
开发指南我去找找
to zw84611
我就是不想申明这种类型的变量,我想在子函数中声明类似c那种的static
变量.不过,看来没戏了!
 
to Yves
我这有delphi开发指南(不知道是不是你说的开发人员指南)的配书源码,不过我没书
总共几十章,几百个例子,根本无从去找,请问你说的那个例子在第几章?
 
to zw84611
奇怪,我的搜索代码和你的一模一样,但为什么调试的时候,你的能行,而我的不行呢?
 呵呵,值得研究!!(一定是我马大哈,哪里出了小问题了)
 谢谢你,难得你在那篇贴子里面独战群雄。先给你加上50分先
 
to zw84611
顺便问一句,给你加的分有没收到?
 
只要你不找子目的话:有一个决对省劲的办法,动态创建一个FILElistBOX不就完了,它比任何方法都快,
 
2:
function FuncSome: Integer;
{$J+}
const
StaticInt: Integer = 0;
{$J-}
begin
Result := StaticInt;
Inc(StaticInt);
end;

1:
type
TForm1 = class(TForm)
Button1: TButton;
CheckBox1: TCheckBox;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
type
TCallBackFind = function(const Path, FileName: string;
Param: Pointer): Boolean;
stdcall;
PFindFile = ^TFindFile;
TFindFile = record
Path: string;
Param: Pointer;
Callback: TCallBackFind;
end;

function FindFileThread(Find: PFindFile): DWORD;
stdcall;
functiondo
Callback(const Path, FileName: string): Boolean;
begin
Result := False;
if Assigned(Find^.Callback) then
Result := Find^.Callback(Path, FileName, Find^.Param);
end;

function SearchPath(const Path: string): Boolean;
var
Rec: TSearchRec;
begin
Result := True;
if FindFirst(Path + '/*.*', faAnyFile, Rec) = 0 then
try
repeat
if (Rec.Name <> '.') and (Rec.Name <> '..') then
begin
if (Rec.Attr and faDirectory) = faDirectory then
Result := SearchPath(Path + '/' + Rec.Name)
else
Result :=do
Callback(Path, Rec.Name);
if not Result then
break;
end;
until FindNext(Rec) <> 0;
finally
FindClose(Rec);
end;
end;

begin
Result := 0;
if not Assigned(Find) then
Exit;
try
SearchPath(Find^.Path);
finally
FreeMem(Find);
end;
end;

procedure FindAllFile(const Path: string;
Callback: TCallbackFind;
Param: Pointer);
var
Find: PFindFile;
ThreadID: Cardinal;
begin
New(Find);
Find^.Path := Path;
Find^.Param := Param;
Find^.Callback := Callback;
CloseHandle(CreateThread(nil, 0, @FindFileThread, Find, 0, ThreadID));
end;

function FindCall(const Path, FileName: string;
Form: TForm1): Boolean;
stdcall;
begin
Result := Form.CheckBox1.Checked;
if Result then
Form.Memo1.Lines.Add(Format('Path: %s, FileName: %s', [Path, FileName]));
//Application.ProcessMessages;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
CheckBox1.Checked := True;
FindAllFile('c:', @FindCall, Self);
end;
 
to 活化石
  呵呵 ,大哥,这样不太好吧
 
感谢copy_paste发过这么长一段代码,
还没来得及细看,先给上20分先
其实这个问题我已经解决了,留下30分我想把我以前提的几个问题拿出来讨论讨论
1。怎样使一个TIcon类的图标在输出为文件时(SaveToFile)不是16色(保持256色)呢?
我用ExtractIconEx得到应用程序的图标,但保存时只能是16色的,唉!
2、在用MciSendString做CD播放器,请问如何在播放完一首后自动播放下一首.

 
没办法,我习惯了先解决,后思考.我觉得如果这个问题不是软件中最核心的要求,未尝不可
 
多人接受答案了。
 
顶部