progressbar çalışmıyor.
Kod: Tümünü seç
type
TFileKontor = class(TThread)
private
protected
procedure Execute; override;
procedure Dosyasayim(root: String);
public
Dirs : TStringList;
end;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
ProgressBar1: TProgressBar;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure Tarama(Dir:String);
public
{ Public declarations }
DirCount : integer;
FileName : String;
FilesCount : integer;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
Procedure TFileKontor.Execute;
var
i : integer;
begin
Form1.FilesCount := 0;
for i := 0 to Dirs.Count-1 do
begin
if FileExists(Dirs[i]) then
begin
Form1.FilesCount := Form1.FilesCount + 1;
end
else
begin
if DirectoryExists(Dirs[i]) then
Dosyasayim(Dirs[i]);
end;
end;
Form1.FilesCount := Form1.FilesCount;
end;
procedure TFileKontor.Dosyasayim(root: String); // PROGRESS BAR İÇİN
var
SR: TSearchRec;
begin
root := IncludeTrailingPathDelimiter(root);
if FindFirst(root + '*.*', faAnyFile, SR) = 0 then
try
repeat
if (SR.Attr and faDirectory) <> 0 then
begin
if (SR.Name <> '.') and (Sr.Name <> '..') then
Dosyasayim(root + SR.Name);
end else
begin
Form1.FilesCount := Form1.FilesCount + 1;
end;
until FindNext(SR) <> 0;
finally
FindClose(SR);
end;
end;
procedure TForm1.Tarama(Dir:String);
var
SR : TSearchRec;
vn : pchar;
ret,i : integer;
begin
Dir := IncludeTrailingPathDelimiter(Dir);
if FindFirst(Dir + '*.*', faAnyFile, SR) = 0 then
begin
try
repeat
inc(DirCount);
if (SR.Attr and faDirectory) <> 0 then
begin
if (SR.Name <> '.') and (Sr.Name <> '..') then
Tarama(Dir + SR.Name);
end else
begin
FileName := Dir + SR.Name;
Application.ProcessMessages;
Form1.ProgressBar1.Max := FilesCount;
ListBox1.Items.Add(FileName);
end;
until FindNext(SR) <> 0;
finally
FindClose(SR);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Path: string;
FICN: TFileKontor;
i: Integer;
begin
Path := 'C:\Program Files';
ProgressBar1.Position := 0;
ProgressBar1.Max := 100;
FICN := TFileKontor.Create(true);
FICN.Dirs := TStringList.Create;
FICN.Dirs.Add(Path);
FICN.Resume;
if (DirectoryExists(Path)) then
begin
Tarama(Path);
end;
end;
end.