需要引入system.ZLib包
procedure TFormMain1.Button25Click(Sender: TObject); //压缩 var LInput, LOutput: TFileStream; LZip: TZCompressionStream; begin inherited; LInput := TFileStream.Create(Edit2.Text, fmOpenRead); //需要压缩的文件 LOutput := TFileStream.Create(Edit3.Text + ‘.zip‘, fmCreate); //压缩完成的文件 LZip := TZCompressionStream.Create(LOutput); LZip.CopyFrom(LInput, LInput.Size); LZip.Free; LInput.Free; LOutput.Free; end; procedure TFormMain1.Button26Click(Sender: TObject); //解压 var LInput, LOutput: TFileStream; LUnZip: TZDecompressionStream; begin { Create the Input, Output, and Decompressed streams. } LInput := TFileStream.Create(Edit2.Text, fmOpenRead); //解压的文件 LOutput := TFileStream.Create(ChangeFileExt(Edit3.Text, ‘.txt‘), fmCreate); //解压后的文件 LUnZip := TZDecompressionStream.Create(LInput); { Decompress data. } LOutput.CopyFrom(LUnZip, 0); { Free the streams. } LUnZip.Free; LInput.Free; LOutput.Free;