In the previous post I have mostly talked about Enex (Enumerable Extensions) I have enabled for all DeHL’s collection classes. Now I will list the other changes that got into this release that may be of interest to you:
- Enex (Enumerable Extensions) in DeHL.Collections.Enex. Support for chained queries, predicates and selectors.
- THashTree (A tree that uses hashes to access the child nodes). in DeHL.Collections.HashTree.
- TConverter can be created with given IType‘s as opposed from the default ones.
- TSuppressedWrapperType which can be used to wrap another IType. It’s main function is to forward all calls to the enclosed IType except the Cleanup() and Management() ones. This way you can use temporary collections inside your collection without the “cleanup” problem.
- Fixed 2 bugs in Resize() method of THashSet and TDictionary which resulted in corrupted heap in some cases.
- TLinkedList properties called First and Last were renamed to FirstNode and LastNode to avoid naming conflicts with Enex’s First() and Last() methods.
- Fixed a bug in TQueue‘s enumerator object. It enumerated the queue’s elements quite wrong.
- Renamed TScopedPtr to a better name: Scoped.
- Added a new type: Nullable. It can be used to represent a NULL value for non-object types such as Integer.
- New life-time extensions for TRefCountedObject. Each ref-counted object can now “keep-alive” other ref-counted objects. This was an useful addition in order to support query-chains in Enex.
How to use the new Nullable<> type:
function GetTheSum(const AList: TList<Integer>): Nullable<Integer>; begin { Check if the list is non-null and has elements } if (AList = nil) or (AList.Count = 0) then Result.MakeNull(); else Result := AList.Sum(); end; var LSum: Nullable<Integer>; begin { ... } LSum := GetTheSum(...); if not LSum.IsNull then WriteLn(LSum.Value); end;
I agree, this is not the best example, but it is OK to get you started. Nullable values are useful when you function may return or even accept a normal (let’s say Integer) value or a NULL.