作者在 2010-01-25 17:10:53 发布以下内容
unit MainUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, FileCtrl;
type
TMainForm = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Edit1Change(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
S: String;
implementation
{$R *.DFM}
procedure TMainForm.Edit1Change(Sender: TObject);
begin
if Edit1.Text<> '' then
begin
Button1.Enabled:= True;
Button2.Enabled:= True;
Button3.Enabled:= True;
end
else
begin
Button1.Enabled:= False;
Button2.Enabled:= False;
Button3.Enabled:= False;
end;
end;
procedure TMainForm.Button1Click(Sender: TObject);
begin
S:= Edit1.Text;
if SelectDirectory(S, [sdAllowCreate, sdPerformCreate, sdPrompt], 0) then
Edit1.Text:= S;
end;
procedure TMainForm.Button2Click(Sender: TObject);
begin
if DirectoryExists(Edit1.Text) then
ShowMessage('该文件夹已经存在')
else
begin
if MessageDlg('建立新建文件夹'+ Edit1.Text+ '?', mtConfirmation, [mbYes, mbNo], 0)= mrYes then
ForceDirectories(Edit1.Text);
end;
end;
procedure TMainForm.Button3Click(Sender: TObject);
begin
if DirectoryExists(Edit1.Text) then
begin
if MessageDlg('删除文件夹'+ Edit1.Text+ '?', mtConfirmation, [mbYes, mbNo], 0)= mrYes then
begin
if S<> Edit1.Text then
RmDir(Edit1.Text)
else
ShowMessage('该文件夹正在使用');
end
end
else
MessageDlg('该文件夹不存在', mtError, [mbOk], 0);
end;
end.