помогите решить проблему в делфи!!!!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, FileCtrl;
type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
Label2: TLabel;
Label3: TLabel;
Button2: TButton;
Edit1: TEdit;
Edit2: TEdit;
Memo1: TMemo;
label4: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
FileName: string;
cDir: string;
n: Integer;
procedure Find;
var
SearchRec: TSearchRec;
begin
GetDir (0,cDir);
if cDir[Length(cDir)] '\' then cDir := cDir+'\';
repeat
if (SearchRec.Attr and faAnyFile) = SearchRec.Attr
then begin
Form1.Memo1.Lines.Add (cDir + SearchRec.Name);
n:=n+1;
end;
until FindNext(SearchRec)0;
if FindFirst('*', faAnyFile, SearchRec) = 0 then
repeat
if (SearchRec.Attr and faDirectory) = faDirectory
then
if SearchRec.Name [1] '.' then
begin
ChDir(SearchRec.Name);
end;
until FindNext(SearchRec) 0;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if not DirectoryExists (Edit2.Text) then
begin
ShowMessage (' Каталог указан неверно');
Edit2.SetFocus;
Exit;
end;
Button1.Enabled:= False;
label4.Caption:= '';
label4.Repaint;
Memo1.Clear;
label4.Caption:= '';
FileName:= Edit1.Text;
cDir:= Edit2.Text;
n:=0 ;
ChDir (cDir);
Find;
if n=0 then
ShowMessage ('Файлов, удовлетворяющих критерию '+'поиска нет. ')
else Label4.Caption:= 'Найдено файлов: '+ IntToStr(n);
Button1.Enabled:= True;
end;
function GetPath (mes: string): string;
var
Root: string;
pwRoot: PWideChar;
Dir: string;
begin
Root:= '';
GetMem(pwRoot, (Length(Root)+1)*2);
pwRoot:= StringToWideChar(Root, pwRoot,MAX_PATH*2);
if SelectDirectory(mes, pwRoot, dir)
then
if Length(Dir)=2
then GetPath:= Dir+'\'
else GetPath:= Dir
else
GetPath:='';
end;
procedure TForm1.Button2Click(Sender: TObject);
var
Path: string;
begin
Path:= GetPath('Выберите папку');
if Path''
then Edit2.Text:= Path;
end;
end.
программа пошла и вот такой у нее получился вид:
когда пишем каталог, например d\
выбираем файл, как на экране, через кнопку Найти
нажимаем кнопку Обзор и выдает ошибку
что делать? ((((