Sample code for 30+ languages & platforms
Delphi DLL

Append Encoded Binary Data to StringBuilder

Demonstrates how to append encoded binary data to the contenets of a StringBuilder.

Chilkat Delphi DLL Downloads

Delphi DLL
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, BinData, StringBuilder;

...

procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
bd: HCkBinData;
sb: HCkStringBuilder;

begin
success := False;

bd := CkBinData_Create();

success := CkBinData_LoadFile(bd,'qa_data/jpg/starfish.jpg');
if (success = False) then
  begin
    Memo1.Lines.Add('Failed to load file.');
    Exit;
  end;

// For example, let's say we want construct simple JSON containing the base64 representation of the above JPG file.
sb := CkStringBuilder_Create();
CkStringBuilder_Append(sb,'{ "jpg": "');
// GetEncodedSb appends the enocded representation of the binary data to the StringBuiler passed in the 2nd arg.
CkBinData_GetEncodedSb(bd,'base64',sb);
CkStringBuilder_Append(sb,'" }');

Memo1.Lines.Add(CkStringBuilder__getAsString(sb));

// Output looks like this:
//  { "jpg": "/9j/4AAQSkZJRgABAg...rcQ+vo//2Q==" }

CkBinData_Dispose(bd);
CkStringBuilder_Dispose(sb);

end;