![]() |
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) Transition from BeginCompressStringENC to FirstChunk/LastChunkProvides instructions for replacing deprecated BeginCompressStringENC method calls with using FirstChunk/LastChunk properties. 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; sbCompressedBase64: TChilkatStringBuilder; compress: TChilkatCompression; sbIndex: TChilkatStringBuilder; i: Integer; originalText: WideString; bdCompressed: TChilkatBinData; sbUncompressedChunk: TChilkatStringBuilder; begin success := 0; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. sbCompressedBase64 := TChilkatStringBuilder.Create(Self); compress := TChilkatCompression.Create(Self); compress.Algorithm := 'deflate'; compress.Charset := 'utf-8'; compress.EncodingMode := 'base64'; sbIndex := TChilkatStringBuilder.Create(Self); // ---------------------------------------------------------------------------------- // This is the deprecated way of compressing in chunks using Begin/More/End methods.. // ---------------------------------------------------------------------------------- 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 sbCompressedBase64.Append(compress.BeginCompressStringENC(sbIndex.GetAsString())); end else begin sbCompressedBase64.Append(compress.MoreCompressStringENC(sbIndex.GetAsString())); end; sbCompressedBase64.Append(compress.MoreCompressStringENC(': This is a line of data to be compressed...' + #13#10)); end; // Flush any remaining output. sbCompressedBase64.Append(compress.EndCompressStringENC()); Memo1.Lines.Add('The base64 encoded compressed text:'); Memo1.Lines.Add(sbCompressedBase64.GetAsString()); // Decompress in one call: originalText := compress.DecompressStringENC(sbCompressedBase64.GetAsString()); Memo1.Lines.Add(originalText); // ---------------------------------------------------------------------------------- // This is new way of compressing in chunks using FirstChunk and LastChunk properties // ---------------------------------------------------------------------------------- sbCompressedBase64.Clear(); compress.FirstChunk := 1; compress.LastChunk := 0; bdCompressed := TChilkatBinData.Create(Self); sbUncompressedChunk := TChilkatStringBuilder.Create(Self); 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; Memo1.Lines.Add('The base64 encoded compressed text:'); Memo1.Lines.Add(bdCompressed.GetEncoded('base64')); // Decompress in one call: originalText := compress.DecompressStringENC(bdCompressed.GetEncoded('base64')); Memo1.Lines.Add(originalText); end; |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.