Sample code for 30+ languages & platforms
Lazarus Pascal

Appending Strings to BinData

Demonstrates appending strings to a BinData..

Chilkat Lazarus Pascal Downloads

Lazarus Pascal
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.BinData;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  binData1: TBinData;
  binData2: TBinData;

begin
  binData1 := TBinData.Create;

  //  Append a string using a 1-byte per char encoding
  binData1.AppendString('This is a test','windows-1252');
  WriteLn(binData1.GetEncoded('hex'));
  //  The bytes contained within the binData1 (in hex) are: 54,68,69,73,20,69, ...

  binData2 := TBinData.Create;

  //  Append a string using a 2-byte per char encoding
  binData2.AppendString('This is a test','utf-16');
  WriteLn(binData2.GetEncoded('hex'));
  //  The bytes contained within the binData2 (in hex) are: 54,00,68,00,69,00,73,00,20,00,69,00, ...


  binData1.Free;
  binData2.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.