Chilkat • HOME • Android™ • AutoIt • C • C# • C++ • Chilkat2-Python • CkPython • Classic ASP • DataFlex • Delphi DLL • Go • Java • Node.js • Objective-C • PHP Extension • Perl • PowerBuilder • PowerShell • PureBasic • Ruby • SQL Server • Swift • Tcl • Unicode C • Unicode C++ • VB.NET • VBScript • Visual Basic 6.0 • Visual FoxPro • Xojo Plugin
(Delphi ActiveX) Compress Text Feed to BinaryThis example receives incoming text data in chunks, compresses as a stream, and accumulates the compressed binary data. The purpose is to demonstrate the BeginCompressString, MoreCompressString, and EndCompressString methods.
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Chilkat_TLB; ... procedure TForm1.Button1Click(Sender: TObject); var success: Integer; compressedData: TChilkatBinData; compressedBytes: Array of Byte; compress: TChilkatCompression; sbIndex: TChilkatStringBuilder; i: Integer; originalText: WideString; begin // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. compressedData := TChilkatBinData.Create(Self); compress := TChilkatCompression.Create(Self); compress.Algorithm := 'deflate'; compress.Charset := 'utf-8'; sbIndex := TChilkatStringBuilder.Create(Self); for i := 0 to 24 do begin // Note: It is possible (and normal) for a BeginCompress* or MoreCompress* method to return // an empty string (or 0 bytes). When this happens, the input data is not lost. It will be flushed // in a subsequent call. sbIndex.Clear(); sbIndex.AppendInt(i); if (i = 0) then begin compressedBytes := compress.BeginCompressString(sbIndex.GetAsString()); end else begin compressedBytes := compress.MoreCompressString(sbIndex.GetAsString()); end; compressedData.AppendBinary(compressedBytes); compressedBytes := compress.MoreCompressString(': This is a line of data to be compressed...' + #13#10); compressedData.AppendBinary(compressedBytes); end; // Flush any remaining output. compressedBytes := compress.EndCompressString(); compressedData.AppendBinary(compressedBytes); // Show the compressed data in hex format: Memo1.Lines.Add('The hex encoded compressed text:'); Memo1.Lines.Add(compressedData.GetEncoded('hex')); // Now decompress in one call: compressedBytes := compressedData.GetBinary(); originalText := compress.DecompressString(compressedBytes); Memo1.Lines.Add(originalText); end; |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.