![]() |
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) Replacment for Deprecated Crypt2 Compress FunctionsThe Chilkat Crypt2 compression functions are deprecated and will be removed. This example shows how to duplicate the functionality using the Chilkat Compression class.
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 crypt: TChilkatCrypt2; sb: TChilkatStringBuilder; i: Integer; compressedStr: WideString; bd: TChilkatBinData; compress: TChilkatCompression; decompressedStr: WideString; begin crypt := TChilkatCrypt2.Create(Self); // Create data to be compressed. sb := TChilkatStringBuilder.Create(Self); i := 0; while i < 25 do begin sb.Append('Hello World, this is a test.' + #13#10); i := i + 1; end; // Bzip2 compress the utf-8 byte representation of the string and return the compressed data as base64. crypt.Charset := 'utf-8'; crypt.EncodingMode := 'base64'; compressedStr := crypt.CompressStringENC(sb.GetAsString()); Memo1.Lines.Add(compressedStr); // Result: 4aeUs+4CAABCWmgzMUFZJlNZZ6znBgAAfNeAABJABQBAAIAmZJwAIABwUNNMAAUqoekYjMp4ixF1FlFxF8i5i1FvFwizF9iwi9RdxaizF7RZi6i0ixF3Fui/i7kinChIM9ZzgwA= // The result contains an 8-byte header composed of a 4-byte magic number (0xB394A7E1) and a 4-byte length. // Do the following to BZip2 decompress using Chilkat Compression bd := TChilkatBinData.Create(Self); bd.AppendEncoded(compressedStr,'base64'); // Remove the 8-byte header. bd.RemoveChunk(0,8); // Decompress compress := TChilkatCompression.Create(Self); compress.Algorithm := 'bzip2'; compress.DecompressBd(bd.ControlInterface); // Get the decompressed string. decompressedStr := bd.GetString('utf-8'); Memo1.Lines.Add(decompressedStr); end; |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.