« Apesuite Beta 4 Released | Main | Awesome stuff with TSVG »
Friday
Feb172012

Duck Duck Delphi Release 3

We are pleased to announce the 3rd release of Duck Duck Delphi.  This udpate provides significant changes and enhancements, adding both flexability and power to the framework.

The biggest enhancement is in respect to Interfaces.  Now you can ask if your objects can impersonate an interface, even if it does not implement one.  An object that can impersonate an interface is one that implements all of the interface's methods and properties with compatible signatures.  

For example,

IMath = interface(IInterface)

  function Add(A,B) : integer;

  function Subtract(A, B) : integer;

end;

TMyObject = class(TObject) // does not implement IMath

  function Add(A,B) : integer;

  function Subtract(A, B) : integer;

end;

......

var

  obj : TMyObject;

  bOkToAdd : boolean;

begin

  obj := TMyObject.Create;

  bOKToAdd := obj.impersonates<IMath>;

 end;

 

 

 

 

Also new to the framework is simplified access to those interface methods:

if obj.impersonates<IMath> then

  Result := obj.asA<IMath>.add(1,5);

 

 

(For those of you who complained that Duck Duck Delphi was less about Duck Typing and more about reflection, perhaps this will help to sway some of those concerns.)

Most of the other changes and fixes have been detailed in our changelog below:

 

+ Added asA<I> to return a custom variant wrapper around the object allowing it to be called as though it were the interface supplied without using the duck interface methods. allowing you to see if the object has all of the methods and properties required of the interface even if it doesn't implement the interface.
+ Added impersonates<I> check to the object class helper allowing you to see if the object has all of the methods and properties required of the interface even if it doesn't implement the interface.
+ Added several overloads to better support indexed properties
+ Added eachProperty and eachMethod iterators to the TRTTI class.
+ Added selector comparisson functions, equalTo, notEqualTo, moreThan, and lessThan.
+ Added new duck functions to return selectors including: this (the same object via selector), related (all related objects, note that this is the same as "all" used to be), props (all object properties of the object), go (executes a method and returns a selector of the result.
* Altered duck.all to return all related objects as well as any properties of type TObject.
+ Added new selector functions First, Last, Middle, Even, Odd which return new selectors filtered accordingly.
+ Added new selector function "use" which alters the current context of the selector.
+ Added new selector action function "replace" which alters the value of a property only if it matches the value supplied
+ Added new duck procedure "replace" which altersthe value of a property only if it matches the value supplied
* Fixed isa.  It's implementation had gone missing.
* Renamed parameters in TRTTI from ctrl to obj.  ctrl was a holdover from when the class was written to work only on TControl descendants and no longer made sense.
* Changed all methods called "sett" to "setTo" due to Nick Hodges consistent badgering and the overwheming will demonstrated by a very scientific facebook poll.
+ Added new setTo functions on Selector and Duck to allow setting of multiple properties via TPropValue array.
+ Added new asValue class method to TRTTI to simplify convertion to TValue where needed.
+ Started documenting TRTTI class