*.*;SaveDialog的名称为SaveDlg;SpinEdit1的Value=1440,MinValue=1440,MaxValue=1600, Increment=1;在“合并”按钮左边的控件是ListBox,名称ListBox1,ListBox1的Sorted=True;其它控件:一个TImage控件,2个Tedit和5个Tbutton,其属性从略。
3. 压缩助理程序的实现
从上到下五个命令按钮的代码依次如下:
//选择待分割的文件
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDlg.Execute then
begin
Edit1.Text := OpenDlg.FileName;
end;
end;
//设置分割后的切片文件的存储位置
//SelectDirectory函数声明在FileCtrl单元中
procedure TForm1.Button2Click(Sender: TObject);
var
Dir: string;
begin
if SelectDirectory('选择存储目录:', '', Dir) then
begin
Edit2.Text := Dir + '\';
end;
end;
//分割文件为切片文件,自动命名
procedure TForm1.Button3Click(Sender: TObject);
var
I, K, Rest, Len: Integer;
AF, BF: TFileStream; //文件流对象
Fn: string; //文件名
Buf : Integer; //单碟容量
begin
if (Edit1.Text = '') or (Edit2.Text = '') then
begin
Beep;
Exit;
end;
//单蝶容量计算为字节数
buf := SpinEdit1.Value * 1024;
I := 1;
try
Af := TFileStream.Create(Edit1.Text, fmOpenRead);
K := Af.Size div Buf;
Rest := Af.Size - K * Buf;
For I := 1 to K do
begin
Fn := Edit2.Text + IntToStr(I) + '.spt'; //文件名
Bf := TFileStream.Create(Fn, fmCreate);
Bf.CopyFrom(Af, Buf);
Bf.Free;
end;
if Rest > 0 then
begin
Fn := Edit2.Text + IntToStr(I) + '.spt';
Bf := TFileStream.Create(Fn, fmCreate);
Bf.CopyFrom(Af, Rest);
Bf.Free;
end;
finally
AF.Free;
end;
end;
//将分割后的切片文件装入到ListBox1中
procedure TForm1.Button4Click(Sender: TObject);
var
I : Integer;
begin
if OpenDlg1.Execute then
For I := 0 to OpenDlg1.Files.Count - 1 do
ListBox1.Items.Add(OpenDlg1.files[I]);
end;
//合并切片文件并保存合并结果
procedure TForm1.Button5Click(Sender: TObject);
var
Af, Bf: TFileStream; //文件流对象
Fn, Ft: string; //文件名
I : Integer;
begin
if ListBox1.Items.Count = 0 then
begin
Beep;
Exit;
end;
if SaveDlg.Execute then
begin
Fn := SaveDlg.FileName;
try
Af := TFileStream.Create(Fn, fmCreate);
For I := 0 to ListBox1.Items.Count -1 do
begin
Ft := ListBox1.Items[I];
Bf := TFileStream.Create(Ft, fmOpenRead);
Af.CopyFrom(Bf, Bf.Size);
Bf.Free;
end;
finally
Af.Free;
end;
end;
end;
上述代码在Windows98,Delphi5.0下调试通过。
……