Test your Delphi knowledge: Exception handling

With this code, what will happen:

program FunWithDelphi;

{$APPTYPE CONSOLE}

uses
  Controls, SysUtils;

begin
  try
    raise TMouse.Create;
  except
    on E:Exception do
    begin
      Writeln(E.Classname, ': E is Exception');
    end;
    on E:TObject do
    begin
      Writeln(E.Classname, ': E is TObject');
    end;
    on E:TMouse do
    begin
      Writeln(E.Classname, ': E is TMouse');
    end;
  end;
  ReadLn;
end.
  • the program will print “TMouse: E is Exception”
  • the program will print “TMouse: E is TObject”
  • the program will print “TMouse: E is TMouse”
  • compilation fails
  • the program will terminate with a runtime error

Continue reading

Indy 10.6 HTTPS POST example with JSON body

The Indy (Internet Direct) TIdHTTP now creates a default SSLIOHandler when requesting an HTTPS url. This makes TIdHTTP a little easier to use “out of the box”. (blog article).

The code below sends a hard-coded JSON object as POST body to a secure url. Note: if you need to customize the SSLVersions used, or specify certificates/keys, or use status/password event handlers, then you will still have to explicitly assign an SSLIOHandler component to the TIdHTTP.IOHandler property before sending an HTTPS request.

program JSONPostExample;

{$APPTYPE CONSOLE}

uses
  IdHTTP, IdGlobal, SysUtils, Classes;

var
  HTTP: TIdHTTP;
  RequestBody: TStream;
  ResponseBody: string;
begin
  HTTP := TIdHTTP.Create;
  try
    try
      RequestBody := TStringStream.Create('{"日本語":42}',
        TEncoding.UTF8);
      try
        HTTP.Request.Accept := 'application/json';
        HTTP.Request.ContentType := 'application/json';
        ResponseBody := HTTP.Post('https://httpbin.org/post',
          RequestBody);
        WriteLn(ResponseBody);
        WriteLn(HTTP.ResponseText);
      finally
        RequestBody.Free;
      end;
    except
      on E: EIdHTTPProtocolException do
      begin
        WriteLn(E.Message);
        WriteLn(E.ErrorMessage);
      end;
      on E: Exception do
      begin
        WriteLn(E.Message);
      end;
    end;
  finally
    HTTP.Free;
  end;
  ReadLn;
  ReportMemoryLeaksOnShutdown := True;
end.

Notes:

Program output:

{
  "args": {},
  "data": "{\"\u65e5\u672c\u8a9e\":42}",
  "files": {},
  "form": {},
  "headers": {
    "Accept": "application/json",
    "Accept-Encoding": "identity",
    "Content-Length": "16",
    "Content-Type": "application/json",
    "Host": "httpbin.org",
    "User-Agent": "Mozilla/3.0 (compatible; Indy Library)"
  },
  "json": {
    "\u65e5\u672c\u8a9e": 42
  },
  "origin": "*.*.*.*",
  "url": "https://httpbin.org/post"
}

HTTP/1.1 200 OK

RabbitMQ 3.5.0 free open source message broker released

The RabbitMQ team announced the release of RabbitMQ 3.5.0. This release adds support for priority queues which were available as a plugin before. Performance is improved; in particular messages smaller than configurable size are embedded in the queue index to reduce I/O and memory consumption. Stability of clustering and autoheal partition handling is improved as well. A new pause_if_all_down partition handling mode is added. The management web UI now shows many more I/O statistics. Binary and source distributions of the new release can be found on the download page.

For application integration in Delphi and Free Pascal, Habarisoft offers a commercial client library for RabbitMQ 3.4.0 and newer.

ScroogeXHTML 6.8 – fast RTF to HTML / XHTML converter

Habarisoft is pleased to announce the release of ScroogeXHTML 6.8, a fast RTF to HTML / XHTML converter library for Delphi and Free Pascal.

A off-line demo version, the “Getting Started” guide (PDF) and the complete API documentation are available.

An interactive on-line demo is available for ScroogeXHTML for the Java™ platform. (Please be aware that RTF table conversion is still experimental in the on-line demo and not available for Delphi yet).

 Release notes

  • Added ConvertFields property for field expressions (default False)
  • Added Hyperlink field support class TLinkURIBuilder
  • Added HTML Anchor support
  • Added unit SxConst which declares margins (configurable with SCROOGE_NO_INDENT option)
  • Documentation generated with doxygen 1.8.8
  • Use strict private scope where possible
  • Changed THyperlinkEvent signature to procedure(Sender: TObject; const TextElement: ISimpleDomTextNode) of object
  • Moved TRichEdit conversion to separate class TBTScroogeXHTMLVCL
  • Added HTTPS as protocol for RequireHTTP hyperlink option
  • Removed unused hyperlink option hyHyperlinkFootnotes
  • Tested with Free Pascal 2.6.4
  • Web demo built with Indy 10.6.2

Habari Client libraries release 2015.02

Habarisoft released new versions of Habari Client libraries for Delphi and Free Pascal application integration with free open source message brokers.

Tested with current message broker versions

  • Apache ActiveMQ 5.11.0
  • Apollo 1.7
  • HornetQ 2.4.0.Final
  • Open MQ 5.1 b09
  • RabbitMQ 3.4.3

Fixes

  • The throughput test application uses the subscribe.receipt=true connection parameter to ensure that the broker is ready before the producer starts sending messages

Improvements

  • Connection factory - As a preparation for further code streamlining between library versions, a new API compatible factory class TBTConnectionFactory is included in this version which will replace TBTJMSConnectionFactory in the next major release
  • Password logging – If Log4D logging is enabled, the passcode header value will be not be logged but replaced with *** in the log output
  • Optional units – Several units which are not covered by basic support have been moved to the source/optional directory (BTMessageTransformer*, BTStreamhelper, SSL support units)
  • Refactorings – Refactorings reduce unit dependencies and hard type casts in several places
  • Cleanup – Removed unused procedure TBTStompClient.Connect(const AURI: IURI)
  • Documentation – More documentation improvements and streamlining between library versions

Previous version release notes: Habari Client libraries release 2014.09

unittests.2015.02

 

Habari Client Libraries

 

Indy HTTP server: multipart/form-data file upload example

The Internet Direct (Indy) 10 HTTP server class TIdHTTPServer does support HTTP file upload with multipart/form-data encoding. The solution below is based on code in the Indy and Delphi newsgroups. Please note that a patch in the Indy library is required, as shown on Stackoverflow in Indy MIME decoding of Multipart/Form-Data Requests returns trailing CR/LF.

Usage

If the demo server runs, open a web browser and navigate to the URL http://127.0.0.1:8080, there you will find the upload form

Neue Bitmap

Source

The full source code can be found here: Indy MIME decoding of Multipart/Form-Data Requests returns trailing CR/LF.

Habari Web Components 2.9 released

1 November 2014: Habarisoft released version 2.9 of the Habari Web Components framework for HTTP web applications, based on Internet Direct (Indy). Project home page and demo download:

http://www.habarisoft.com/habari_webcomponents.html

The demo download contains documentation, tutorial project sources and the “Flightplan” executable demo which uses jQuery mobile.

Habari Web Components

Habari Web Components with JclDebug stack trace support

The upcoming release of Habari Web Components 2.9 introduces experimental support for stack trace output with JclDebug, part of the open source Jedi Code Library, in addition to the already included support for madExcept stack traces.

Exception stack traces are available in development stage mode, and require linking with detailled map information. Please note that these experimental features are not covered by the standard basic support scheme for Habari Web Components and not guaranteed to work with all versions of Delphi / Free Pascal.

The screenshots below illustrate the output on screen and in the Log4D logging output:

Habari Web Components

ScroogeXHTML 5 converter: table support on-line demo

15. October 2014 – Habarisoft announces the first on-line demo of its RTF to HTML / XHTML converter ScroogeXHTML 5.0, which introduces table support, at https://secure.habariwebcomponents.de/sxd/index.xhtml.

ScroogeXHTML 5.0 is a small footprint, but high speed, RTF conversion library for Java 7. For Java 5 and higher, Habarisoft offers ScroogeXHTML 4.5.

Unbenannt

ScroogeXHTML is also available for the Android platform. The “Tiny RTF Viewer” app uses ScroogeXHTML 4 and can be found in the Play store at https://play.google.com/store/apps/details?id=com.habarisoft.scroogertfviewer

Google play

Android and Google Play are trademarks of Google Inc.