mainunit.pas
上传用户:psxgmh
上传日期:2013-04-08
资源大小:15112k
文件大小:2k
- unit mainunit;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, ComCtrls, Buttons;
- type
- TForm1 = class(TForm)
- GroupBox1: TGroupBox;
- Label1: TLabel;
- Edit1: TEdit;
- Edit2: TEdit;
- Label2: TLabel;
- BitBtn1: TBitBtn;
- BitBtn2: TBitBtn;
- OpenDialog1: TOpenDialog;
- SaveDialog1: TSaveDialog;
- BitBtn3: TBitBtn;
- BitBtn4: TBitBtn;
- procedure FormCreate(Sender: TObject);
- procedure BitBtn1Click(Sender: TObject);
- procedure BitBtn2Click(Sender: TObject);
- procedure BitBtn4Click(Sender: TObject);
- procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- procedure BitBtn3Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- Copying:Boolean;
- implementation
- {$R *.dfm}
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- OpenDialog1.FileName:='';
- OpenDialog1.InitialDir:=ExtractFileDir(Application.ExeName);
- SaveDialog1.FileName:='';
- SaveDialog1.InitialDir:=ExtractFileDir(Application.ExeName);
- BitBtn3.Enabled:=False;
- Copying:=False;
- end;
- procedure TForm1.BitBtn1Click(Sender: TObject);
- begin
- With Opendialog1 do
- if Execute then
- Edit1.Text:=Opendialog1.FileName;
- if ((Edit1.Text<>'') and (Edit2.Text<>'')) then
- BitBtn3.Enabled:=True
- else
- BitBtn3.Enabled:=False;
- end;
- procedure TForm1.BitBtn2Click(Sender: TObject);
- begin
- With SaveDialog1 do
- if Execute then
- Edit2.Text:=Savedialog1.FileName;
- if ((Edit1.Text<>'') and (Edit2.Text<>'')) then
- BitBtn3.Enabled:=True
- else
- BitBtn3.Enabled:=False;
- end;
- procedure TForm1.BitBtn4Click(Sender: TObject);
- begin
- Close;
- end;
- procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- begin
- if Copying then
- CanClose:=False
- else
- CanClose:=True;
- end;
- procedure TForm1.BitBtn3Click(Sender: TObject);
- var
- FromFile,ToFile:TFileStream;
- begin
- FromFile:=TFileStream.Create(Edit1.Text,fmOpenRead);
- try
- ToFile:=TFileStream.Create(Edit2.Text,fmCreate);
- BitBtn3.Enabled:=False;
- Copying:=True;
- try
- ToFile.CopyFrom(FromFile,0);
- ShowMessage('复制文件过程成功完成.')
- finally
- BitBtn3.Enabled:=True;
- ToFile.Free
- end
- finally
- FromFile.Free;
- Copying:=False
- end
- end;
- end.