![]() |
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. Note: This example requires Chilkat v11.0.0 or greater.
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; bdCompressed: TChilkatBinData; compress: TChilkatCompression; sbUncompressedChunk: TChilkatStringBuilder; i: Integer; bdDecompressed: TChilkatBinData; originalText: WideString; begin success := 0; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. bdCompressed := TChilkatBinData.Create(Self); compress := TChilkatCompression.Create(Self); compress.Algorithm := 'deflate'; compress.Charset := 'utf-8'; sbUncompressedChunk := TChilkatStringBuilder.Create(Self); compress.FirstChunk := 1; compress.LastChunk := 0; for i := 0 to 24 do begin if (i = 24) then begin compress.LastChunk := 1; end; sbUncompressedChunk.Clear(); sbUncompressedChunk.AppendInt(i); sbUncompressedChunk.Append(': This is a line of data to be compressed...' + #13#10); compress.CompressSb(sbUncompressedChunk.ControlInterface,bdCompressed.ControlInterface); compress.FirstChunk := 0; end; // Show the compressed data in hex format: Memo1.Lines.Add('The hex encoded compressed text:'); Memo1.Lines.Add(bdCompressed.GetEncoded('hex')); // Now decompress in one call. It is important to set both FirstChunk and LastChunk = 1 bdDecompressed := TChilkatBinData.Create(Self); compress.FirstChunk := 1; compress.LastChunk := 1; success := compress.DecompressBd2(bdCompressed.ControlInterface,bdDecompressed.ControlInterface); if (success = 0) then begin Memo1.Lines.Add(compress.LastErrorText); Exit; end; originalText := bdDecompressed.GetString('utf-8'); Memo1.Lines.Add(originalText); end; |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.