Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Delphi ActiveX Examples

ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
Facebook
Firebase
GMail REST API
GeoOp
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Sheets
Gzip
HTML-to-XML/Text
HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)

Jira
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
PayPal
Peoplevox
QuickBooks
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Shopify
Socket/SSL/TLS
Spider
Stream
Stripe
SugarCRM
Tar Archive
Twitter
Upload
VoiceBase
Walmart
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Xero
Zip
curl
eBay

 

 

 

(Delphi ActiveX) Compress String Feed to Base64

This example receives incoming text data in chunks, compresses as a stream, and accumulates the compressed data in base64.

The purpose is to demonstrate the BeginCompressStringENC, MoreCompressStringENC, and EndCompressStringENC methods.

Chilkat for Delphi Downloads

Chilkat ActiveX DLL for Delphi

Chilkat non-ActiveX DLL for Delphi

* The examples here use the ActiveX DLL.

uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Chilkat_v9_5_0_TLB;

...

procedure TForm1.Button1Click(Sender: TObject);
var
success: Integer;
sbCompressedBase64: TChilkatStringBuilder;
compress: TChilkatCompression;
sbIndex: TChilkatStringBuilder;
i: Integer;
originalText: WideString;

begin
//  This example requires the Chilkat API to have been previously unlocked.
//  See Compression UnlockComponent 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);

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());

//  Now decompress in one call:
originalText := compress.DecompressStringENC(sbCompressedBase64.GetAsString());
Memo1.Lines.Add(originalText);
end;

 

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