« Awesome stuff with TSVG | Main | Apesuite Refactoring »

Duck Duck Delphi

In case you missed it, yesterday we released to open source a new project called Duck Duck Delphi. We are using the code a good deal in our Apesuite refactoring and the new project is actually born from that work.  It is probably the single most useful unit I've ever written and I expect to find myself using it in nearly everything I write from this point forward.  

As a long time Delphi developer, I've always been a huge fan of RTTI.  One of the first internet projects I wrote back in the late 90's involved serializing delphi objects across HTTP to create a remoting api for an ERP application.  It was a great project that taught me a lot about the internals of the Delphi framework and the power you can get from knowing more about your objects at runtime.

In recent years I've had occasion to learn and use Ruby.  While it's true that it's a scripting language, it's beautiful and consistent syntax, language structure and overall architecture really won me over.  I really enjoy Ruby and just how powerful it really is.  It was my first exposure to closures, lambdas and ducktyping... all things that took me some time to wrap my head around, but once it clicked, it was over. How could I ever code without them?

Delphi has since made several advancements making it easier to code in a Ruby-like way.  The biggest IMO was the addition of anonymous methods.  Generics also made it easier to code without knowing a specific type at design-time and Enhanced RTTI made it possible, though extremely cumbersome, to perform some simple ducktyping. Class Helpers and VMTInterceptors made it possible to inject ad intercept functionality of undetermined objects at runtime.

Enter DuckDuckDelphi...

This project aims to take the language enhancements of recent Delphi versions and create an environment that simplifies duck-typing and other Ruby-like coding paradymes within the Delphi world. This project simplifies:


if obj.duck.has('property') and obj.duck.can('dosomething') then


Inline events:

obj.onclick = Event.Notify( procedure(Sender : TObject)




Chained Object Selectors:



duck.all.each(procedure(obj : TObject) begin

This is just the beginning of what you can do with Duck Duck Delphi and only scratching the surface of where we can go with it.  

Please give it a try. Source Code can be found here and if you have questions, please direct them toward our support site.

I certainly hope you find this project as useful as I have and welcome your feedback.