Posts tagged delphi

TZDB 1.8.2014b

A new version of TZDB has been release (1.8.2014b). This version fixes a few issues around the Windows TZ aliases provided by CLDR project. Obviously the database has been updated to the most recent version (2014b).

 

The biggest news is the fact that we have moved to GitHub! The old Google Code url will still be around for a while, after which point it will be deleted.

 

Also, I would like to thank Pierre Yager for the fixes and the release itself as I do not have access to a Delphi license any longer.

 

TZDB is an open source project that provides Delphi (7+) and FreePascal (2.0+) users with a “built-in” timezone database. The same source of data is used in most Unixes, Java, MacOS and multiple other projects out there.

TZDB 1.8 — 13 November 2012 Database (2012j)

A new version of TZDB has been release (1.8.121113). This version adds some very small changes. The biggest update is the bundled database version.

Grab the latest version here, and view the latest changes here.

 

TZDB is an open source project that provides Delphi (7+) and FreePascal (2.0+) users with a “built-in” timezone database. The same source of data is used in most Unixes, Java, MacOS and multiple other projects out there.

Delphi anonymous methods are …

… too fat.

Surely writing code like this gets frustrating very fast. I want my lambdas!!

  { Lovely, isn't it? }
  LGroupJoined := LOwners.Op.GroupJoin<TPet, TPerson, TOwnedPets>(LPets,
    function(Arg1: TPerson): TPerson begin Result := Arg1; end,
    function(Arg1: TPet): TPerson begin Result := Arg1.FOwner; end,
    function(Arg1: TPerson; Arg2: ISequence<TPet>): TOwnedPets
    begin
      Result.FOwnerName := Format('%s, %s', [Arg1.FLast, Arg1.FFirst]);
      Result.FPetNames := Arg2.Op.Select<String>(
        function(Arg1: TPet): String begin Result := Arg1.FName; end);
    end
  );

  for LOwnedPets in LGroupJoined do
  begin
    WriteLn('Person ', LOwnedPets.FOwnerName, ' owns: ');
    Write('    ');

    for LName in LOwnedPets.FPetNames do
      Write(LName, ', ');

    WriteLn;
  end;

In other news, there is a working version of Collections 2.0 in the SVN. Most of the changes were sitting on my hard drive for a year now. I just made sure that the last touches are applied and that this version compiles in Delphi XE2. I have also applied a few fixes that enabled the package to work in 64 bit environment.

 

Be advised: The unit tests are completely broken. I have no short term plans on making them work. The amount of time needed for that is staggering. I am currently focused on features so I won’t touch them in a while.

 

P.S. I have to say that I am very disappointed with the quality of the IDE when generics are involved. I had countless unpleasant problems in the past but was expecting things to get better in XE2. Not so. My IDE froze countless time when trying to edit some source files. Whenever I would type a “.” or a “(” it would be gone for good. This makes me wonder whether Collections will be usable at all to you guys. With such buggy support I can predict only crashes. And don’t get me started on the EXE size …

Get over the FreeAndNil thing already!

‘Nuff Said!

TZDB 1.7 with 27 June Database

After a few months of inactivity I give you the latest update to TZDB featuring the last published TZ database. This realease also fixes a bug in the importer that could not properly read only hour based offsets which resulted in wrong calculations for some timezones.

For people trying to user Etc\xxxxx time zones. Those time zones have their sign inverted as specified by POSIX. This means that Etc\GMT+2 is actually GMT-2. This is not a bug in TZDB, it’s just the way these pseudo-timezones are defined.

 

For those unaware: TZDB is an open source project that provides Delphi (7+) and FreePascal (2.0+) users with a “built-in” timezone database. The same source of data is used in most Unixes, Java, MacOS and multiple other projects out there.

Grab the latest version here, and view the latest changes here.

Variant Invoke and RTTI

I was “spring cleaning” my temporary project directory on my hard drive today and I found a half-finished implementation of a dynamic dispatch for objects based on new RTTI (Delphi 2010+). I spent some time and fixed the last issues I had and now I think it’s ready to be published.

All the code is enclosed in a single unit (there’s not that much code actually) that exposes one function called “AsDynamic“. This method expects a normal non-nil object, a lifetime management flag and returns a custom Variant value.  The Variant can be used later on to dynamically invoke any method/property on that object.

The following example shows a wrapped TStringList object:

var
  LVarList: Variant;
begin
  { Create a new String List and wrap it into a Variant. By default the Variant will also take care about freeing the object. }
  LVarList := AsDynamic(TStringList.Create);

  { Add two strings to the string list. Note that Add() is called dynamically here. }
  LVarList.Add('Hello World!');
  LVarList.Add('Cool string');

  { Make the list sorted (also dynamically) }
  LVarList.Sorted := True;

  { ... And finally write the contents of the list }
  WriteLn(LVarList.Text);
end.

I don’t see any practical uses this code but it’s good for learning purposes. It can also be a simplified way of treating the cases when one has to execute the same code on classes that do not share a common ancestor or cannot implement an interface.

Just a quick note on what you can see inside the unit:

  • Defining a custom Variant type by extending TInvokeableVariantType and providing the proper support code.
  • An intermediate object and an interface that contain the wrapped object and RTTI structures needed for dynamic invoke. The custom Variant type carries over this object (actually an interface reference).
  • TValue to Variant and Variant to TValue conversion. Since the dynamic dispatch uses variants for arguments a conversion is required in both directions. This is simple in most cases but rather complicated for var and out parameters.

Note that dynamic dispatch as implemented by Delphi has quite a few restriction in what types are allowed and how exactly those values are passed to the invoked methods. For example literals are passed by value and variables are passed by reference (not always!). This is due to the nature of “not knowing” what exactly the method behind expects. As an example, you cannot pass a String by reference while a WideString variable is always passed by reference.

The code can be found here: Dynamic Object Dispatch (2237)

TZDB 1.7 database 14 March

I have finally managed to get some free time on my hands and released the latest update to TZDB containing the latest DB (from 14 March). As usual, no code changes, just data updates.

For those unaware: TZDB is an open source project that provides Delphi (7+) and FreePascal (2.0+) users with a “built-in” timezone database. The same source of data is used in most Unixes, Java, MacOS and multiple other projects out there.

Grab the latest version here, and view the latest changes here.

Collections 1.1 is out

I’m proud to present version 1.1 of Collections package.



The major highlights of this release are:

  • TLinkedDictionary<TKey, TValue>, same as the standard dictionary but with predictable insertion order.
  • TLinkedStack<T>, same as standard set but with some predictability in element order.
  • TBitSet, a sorted set designed to store 16-bit numbers only.
  • TBidiDictionary<TKey, TValue>, a dictionary that enforces one key, one value on both ends.
  • TSortedBidiDictionary<TKey, TValue>, a sorted bidirectional dictionary.
  • TDoubleSortedDictionary<TKey, TValue>, a bidirectional dictionary sorted on both keys and values.
  • TSortedLinkedList<T>, a linked list with automated sorting.
  • RTTI based selectors. See overloads of Op.Select.
  • A rewrite of TLinkedList<T>, TLinkedQueue<T> and TLinkedStack<T>.
  • TArraySet<T> is not a sorted set and optimized a lot.
  • Multiple optimizations all over the place.
  • A new Op.GroupBy<T> operation.
  • Some internal cleanup.
  • Documentation fixes (Thanks Denisa once again).

On the project organization side, the project home page has got quite some love:

  • Three simplified diagrams of classes and interfaces in Collections.
  • A FAQ page that I hope will be useful to people. If you have a question not answered there please leave a comment and I will respond ASAP.
  • A page that states the differences between this project ans stock RTL collections.
  • A list with short descriptions for all Enex operations supported by collections.
  • A detailed “map” of all collections provided by the project with explanations of when to use, some implementation details and etc useful information that can help you better chose the collection you need.

On the documentation side of things, you will find two sample projects in the bundle. Only two at the moment, will add more when I have enough free time to.

Get the latest version or view the changelog!

TZDB 1.7 with latest DB update available.

The good people at “the tz database” project released their first update for this year (2011a).  I have updated TZDB to include the newest update. No code changes in this release (it is the same 1.7 code base), just updated the timezone database.

For those unaware: TZDB is an open source project that provides Delphi (7+) and FreePascal (2.0+) users with a “built-in” timezone database. The same source of data is used in most Unixes, Java, MacOS and multiple other projects out there.

Grab the latest version here, and view the latest changes here.

Collections 1.0.1

I’ve just put the 1.0.1 bug fix version up for download. It fixes XE compatibility issues, documentation fixes (thanks to Denisa Ilascu for her hard work). I don’t have access to Delphi 2010 and can’t say for sure whether it will work (I hope so).

EDIT: Confirmed, it works on Delphi 2010.

Download link here.