unit1.~pas

来自「安装程序时或在打开数据文件时都需要打开文件夹的操作,本例提供创建和删除文件夹的操」· ~PAS 代码 · 共 57 行

~PAS
57
字号
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Buttons, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Label1: TLabel;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
  if (Directoryexists(Edit1.Text)) then
    ShowMessage('文件夹存在')
  else
  begin
    if Application.MessageBox(pchar('是否创建文件夹'+Edit1.Text),'提示',mb_yesno)=mryes then
    begin
      ForceDirectories(Edit1.Text);
      Edit1.Clear;
    end;
  end;
end;

procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
if (DirectoryExists(Edit1.Text)) then
begin
  if Application.MessageBox(pchar('是否创建文件夹'+Edit1.Text),'提示',mb_yesno)=mryes then
  begin
    RmDir(Edit1.Text);
    Edit1.Clear;
  end;
end;
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?