Sample code for 30+ languages & platforms
Lazarus Pascal Requires Chilkat v11.1.0+

HTML Encoding

Demonstrates HTML encoding and decoding.

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.Crypt2;

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

procedure RunDemo;
var
  crypt: TCrypt2;
  s: string;
  htmlEncoded: string;

begin
  crypt := TCrypt2.Create;

  s := '< é ü ç Ω Hello & World ✓ >';

  htmlEncoded := crypt.EncodeString(s,'utf-8','html');
  WriteLn(htmlEncoded);

  //  Output:
  //  < &eacute; &uuml; &ccedil; &ohm; Hello & World &check; >

  //  To decode:
  s := crypt.DecodeString(htmlEncoded,'utf-8','html');
  WriteLn(s);

  //  Output:
  //  < é ü ç Ω Hello & World ✓ >


  crypt.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.