mainunit.pas
上传用户:psxgmh
上传日期:2013-04-08
资源大小:15112k
文件大小:3k
- 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;
- ProgressBar1: TProgressBar;
- Label3: 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:File;
- NumRead,NumWrite:Integer;
- Buf:Array[1..2048] of byte;
- begin
- AssignFile(FromFile,Opendialog1.FileName);
- Reset(FromFile,1);
- AssignFile(ToFile,SaveDialog1.FileName);
- Rewrite(ToFile,1);
- ProgressBar1.Max:=(FileSize(FromFile)*2 div sizeof(buf));
- repeat
- BlockRead(FromFile,Buf,Sizeof(Buf),NumRead);
- ProgressBar1.StepIt;
- BlockWrite(ToFile,Buf,NumRead,NumWrite);
- ProgressBar1.StepIt;
- Copying:=True;
- Application.ProcessMessages;
- until ((NumRead=0) or (NumWrite<>NumRead));
- CloseFile(FromFile);
- CloseFile(ToFile);
- Copying:=False;
- ShowMessage('复制文件过程成功完成.');
- end;
- end.