Duck Duck Delphi
DuckDuckDelphi is an Open Source (MIT License) unit for Delphi XE2 which adds duck typing functionality to a normally strongly typed language.
For more information on Duck Typing, please check out this article on Wikipedia.
With Duck Typing, you accomplish tasks by knowing what an object looks like and what it can do, rather than knowing what it is. For example instead of typing:
if AObject is TEdit then
TEdit(AObject).visible := False;
... you would instead inspect the object to see if it has a visible proprety and act upon it regardless the type...
if AObject.duck.has('visible') then
This alone is interesting, but what if you wanted to operate on all objects that have a visible property? say for example you wanted to hide all objects on a form...
This code iterates through all objects on the form and sets the ones that have a "visible" property to false, regardless their type.
What if you want to clear all memos, text edits, etc on a form via a buttonclick?
procedure TForm1.Button2Click(Sender: TObject);
pretty simple, eh?
And this obviously is not limited to visual components or objects of a form. Lets say you have an object list that you want to update en-mass...
var list : TList<TObject>
.... create and fill list ...
Duck typing in a strongly typed language such as Delphi has never been easy. Now you can have the best features of a strongly typed language and yet use duck typing whererever it makes sense.
Give DuckDuckDelphi a try and I'm sure you will find yourself using it in nearly every Delphi project very soon.
The project is hosted on Google Code: