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;