Delphi DLL
Delphi DLL
Transition from BeginCompressStringENC to FirstChunk/LastChunk
Provides instructions for replacing deprecated BeginCompressStringENC method calls with using FirstChunk/LastChunk properties.Chilkat Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, StringBuilder, BinData, Compression;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
sbCompressedBase64: HCkStringBuilder;
compress: HCkCompression;
sbIndex: HCkStringBuilder;
i: Integer;
originalText: PWideChar;
bdCompressed: HCkBinData;
sbUncompressedChunk: HCkStringBuilder;
begin
success := False;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
sbCompressedBase64 := CkStringBuilder_Create();
compress := CkCompression_Create();
CkCompression_putAlgorithm(compress,'deflate');
CkCompression_putCharset(compress,'utf-8');
CkCompression_putEncodingMode(compress,'base64');
sbIndex := CkStringBuilder_Create();
// ----------------------------------------------------------------------------------
// 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.
CkStringBuilder_Clear(sbIndex);
CkStringBuilder_AppendInt(sbIndex,i);
if (i = 0) then
begin
CkStringBuilder_Append(sbCompressedBase64,CkCompression__beginCompressStringENC(compress,CkStringBuilder__getAsString(sbIndex)));
end
else
begin
CkStringBuilder_Append(sbCompressedBase64,CkCompression__moreCompressStringENC(compress,CkStringBuilder__getAsString(sbIndex)));
end;
CkStringBuilder_Append(sbCompressedBase64,CkCompression__moreCompressStringENC(compress,': This is a line of data to be compressed...' + #13#10));
end;
// Flush any remaining output.
CkStringBuilder_Append(sbCompressedBase64,CkCompression__endCompressStringENC(compress));
Memo1.Lines.Add('The base64 encoded compressed text:');
Memo1.Lines.Add(CkStringBuilder__getAsString(sbCompressedBase64));
// Decompress in one call:
originalText := CkCompression__decompressStringENC(compress,CkStringBuilder__getAsString(sbCompressedBase64));
Memo1.Lines.Add(originalText);
// ----------------------------------------------------------------------------------
// This is new way of compressing in chunks using FirstChunk and LastChunk properties
// ----------------------------------------------------------------------------------
CkStringBuilder_Clear(sbCompressedBase64);
CkCompression_putFirstChunk(compress,True);
CkCompression_putLastChunk(compress,False);
bdCompressed := CkBinData_Create();
sbUncompressedChunk := CkStringBuilder_Create();
for i := 0 to 24 do
begin
if (i = 24) then
begin
CkCompression_putLastChunk(compress,True);
end;
CkStringBuilder_Clear(sbUncompressedChunk);
CkStringBuilder_AppendInt(sbUncompressedChunk,i);
CkStringBuilder_Append(sbUncompressedChunk,': This is a line of data to be compressed...' + #13#10);
CkCompression_CompressSb(compress,sbUncompressedChunk,bdCompressed);
CkCompression_putFirstChunk(compress,False);
end;
Memo1.Lines.Add('The base64 encoded compressed text:');
Memo1.Lines.Add(CkBinData__getEncoded(bdCompressed,'base64'));
// Decompress in one call:
originalText := CkCompression__decompressStringENC(compress,CkBinData__getEncoded(bdCompressed,'base64'));
Memo1.Lines.Add(originalText);
CkStringBuilder_Dispose(sbCompressedBase64);
CkCompression_Dispose(compress);
CkStringBuilder_Dispose(sbIndex);
CkBinData_Dispose(bdCompressed);
CkStringBuilder_Dispose(sbUncompressedChunk);
end;