Use Delphi to easily compile the compression Assistant Program

Source: Internet
Author: User
I. Question proposal
WinZip is a commonly used tool for backup and data exchange during computer usage. However, in actual use, I found that WinZip is somewhat unsatisfactory for data exchange operations, such:

1. when a large compressed package is compressed to a floppy disk, the operator must have multiple floppy disks at hand to complete data packet transfer. If there is only one floppy disk at hand, but there is really no way.

2. If an error occurs when writing or reading data from a floppy disk, the previous process must be redone.

3. to read data from a floppy disk on another machine, you must install WinZip on the machine.

Is there a good solution to avoid the above error-prone and cumbersome software installation process? Therefore, the author uses Delphi5.0 to compile a compression Assistant Program to provide an auxiliary method and means for data exchange.

Ii. Basic Idea of compressing Assistant Program Design

The compression tool compresses the files to be exchanged between different computers and converts them into a self-extracting format, the decompressed package is split into multiple files stored on the hard disk in the unit of floppy disk capacity by the compression Assistant program. In this way, by using the Copy command and a floppy disk, You can exchange data between computers with Large Compressed packages. Then, the compression Assistant program can merge the above files on another machine, it becomes a self-extracting file format, avoiding the tedious process of installing WinZip software. The preceding problems can be solved by compressing the Assistant Program.

Iii. Implementation Method

1. Programming Interface

2. Control property settings

Borderstyle = bsdialog;
The two opendialog controls are named opendlg and opendlg1 respectively;
Set ofallowmultiselect = true in the options attribute of opendlg1,
Set the filter attribute to split file (*. SPT) | *. SPT | all file (*. *) | *.*;
Savedialog name: savedlg; Value of spinedit1 = 1440, minvalue = 1440,
Maxvalue = 1600, increment = 1; the control on the left of the merge button is ListBox,
The name is listbox1, And the sorted value of listbox1 is true. Other controls: A timage control,
2 tedit and 5 tbutton, whose attributes are omitted.
 

3. Implementation of the compression Assistant Program

The code for the top five command buttons is as follows:

// Select the file to be split
Procedure tform1.button1click (Sender: tobject );
Begin
If opendlg. Execute then
Begin
Edit1.text: = opendlg. filename;
End;
End;

// Set the storage location of the split slice File
// Selectdirectory function declaration in filectrl Unit
Procedure tform1.button2click (Sender: tobject );
VaR
Dir: string;
Begin
If selectdirectory ('select the storage directory: ', '', DIR) then
Begin
Edit2.text: = dir + '/';
End;
End;

// The split file is a sliced file and is automatically named
Procedure tform1.button3click (Sender: tobject );
VaR
I, K, rest, Len: integer;
AF, BF: tfilestream; // file stream object
FN: string; // file name
Buf: integer; // disk capacity
Begin
If (edit1.text = '') or (edit2.text ='') then
Begin
Beep;
Exit;
End;
// The size of a single butterfly is measured in bytes.
Buf: = fig * 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'; // file name
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;

// Load the split slice file to 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;

// Merge the slicing file and save the merging result
Procedure tform1.button5click (Sender: tobject );
VaR
AF, BF: tfilestream; // file stream object
FN, ft: string; // file name
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;

The above code is debugged in WindowsXP, Delphi7.0/5.0.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.