Delphi Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CUnicode C++Unicode CMFCDelphi DLLDelphi ActiveXFoxProJavaPerlPHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

Delphi Examples

Bounced Mail
Bz2
Character Encoding
CSV
DKIM / DomainKey
Digital Certificates
Digital Signatures
DH Key Exchange
DSA
Email
Email Object
FTP
HTML Conversion
HTTP
IMAP
Encryption
MHT / HTML Email
NTLM
POP3
RSA
S/MIME
SMTP
Socket
Spider
SFTP
SSH
SSH Key
SSH Tunnel
String
Tar
Upload
XML
XMP
Zip Compression

More Examples...
Amazon S3
Byte Array
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
Bzip2
LZW

Type Conversion

 

Article: Understanding COM References in Delphi

(Delphi) Streaming Deflate String

Demonstrates streaming string compression using the Deflate algorithm. Data may be compressed in chunks by initially calling one of the BeginCompress* methods, followed by 0 or more calls to a MoreCompress* method, and terminating with a call to an EndCompress* method.

Likewise, data may be decompressed by calling a BeginDecompress* method, followed by 0 or more MoreDecompress* calls, and ending with an EndDecompress* method call.

This example demonstrates string-to-string deflate compression and decompression in chunks.

(The deflate algorithm is most commonly used by the .zip file format.)

Download Chilkat Compression ActiveX

uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls,
    CHILKATCOMPRESSIONLib_TLB,
    OleCtrls;

...

procedure TForm1.Button1Click(Sender: TObject);
var
compress: TChilkatCompression;
success: Integer;
strData: String;
i: Integer;
strCompressed: String;
strOriginal: String;
chunk1: String;
chunk2: String;
chunk3: String;
chunk4: String;

begin
compress := TChilkatCompression.Create(Self);

//  Any string argument automatically begins a 30-day trial.
success := compress.UnlockComponent('30-day trial');
if (success <> 1) then
  begin
    Memo1.Lines.Add(compress.LastErrorText);
    Exit;
  end;

compress.Algorithm := 'deflate';
compress.Charset := 'ansi';
compress.EncodingMode := 'base64';

//  Create a long string to compress.
strData := 'abcdefg1122334455667788';
strData := strData + #13#10;

//  Note: BeginCompressStringENC may return a zero-length
//  string.  This is normal if the input is buffered and no
//  compressed data is yet available.
//  However, a null reference indicates an error -- which is
//  generally only possible if the component was never unlocked.
strCompressed := compress.BeginCompressStringENC(strData);

//  Compress 100 more chunks of data.  Each call to
//  MoreCompressStringENC may or may not produce additional
//  compressed output.
for i := 0 to 99 do
  begin
    strData := 'abcdefg1122334455667788';
    strData := strData + #13#10;

    strCompressed := strCompressed + compress.MoreCompressStringENC(strData);
  end;

//  Finalize the compression with a single call to EndCompressStringENC:
strCompressed := strCompressed + compress.EndCompressStringENC();

//  Display the compressed string.
//  The result will be:
//  S0xKTklNSzc0NDIyNjYxMTU1MzM3t7Dg5UoclRiVGJUYlRiVGJUYlRiVGJUYchIA

Memo1.Lines.Add(strCompressed);

//  Decompress back to the original in a single call.

strOriginal := compress.DecompressStringENC(strCompressed);

//  Display the uncompressed original:
Memo1.Lines.Add('--- Original ---');
Memo1.Lines.Add(strOriginal);

//  Inflate in multiple calls.  It doesn't matter how the
//  compressed data is split -- it could be fed to the decompressor
//  one char at a time if desired.
chunk1 := 'S0xKTklNSzc0ND';
chunk2 := 'Iy';
chunk3 := 'NjYxMTU1MzM3t7Dg5UoclRiV';
chunk4 := 'GJUYlRiVGJUYlRiVGJUYchIA';

strOriginal := '';
strOriginal := compress.BeginDecompressStringENC(chunk1);
strOriginal := strOriginal + compress.MoreDecompressStringENC(chunk2);
strOriginal := strOriginal + compress.MoreDecompressStringENC(chunk3);
strOriginal := strOriginal + compress.MoreDecompressStringENC(chunk4);
strOriginal := strOriginal + compress.EndDecompressStringENC();

//  Display the uncompressed original after inflating in chunks:
Memo1.Lines.Add('--- Original after Inflating from Chunks ---');
Memo1.Lines.Add(strOriginal);
end;

 

© 2000-2013 Chilkat Software, Inc. All Rights Reserved.