The problem I’m facing now has totally made me feel like I don’t understand programming at all. I have a TDictionary object which consists of pairs of TDate => TEvent (custom class). The object is used in a class which is shared by two separate applications (they don’t communicate). In one application, the following works correctly:
// Get recipes from the very event.
Tmp := FCalendar.ContainsKey(D);
if (Tmp) then
begin
E := FCalendar[D];
CopyRecipes(E);
end;
On the other hand, the same piece of code doesn’t work in the other application ! How is that possible? I have attached a screenshot of what is happening in the debugger: 
As you can see, the key is present in the dictionary, and yet ContainsKey() returns FALSE.
What is causing this?
Regards,
Patryk.
The reason is that
TDateis actually just aTDateTime. That means it is a double precision value holding number of days since the Delphi epoch. The IDE debug hints for aTDateshow just the date part and omit the time part. You are comparing for equality and so two values that are in the same day, but have different time components will not be equal. Here’s a screenshot to illustrate:Solve the problem by using
DateOfto remove the time part of the date time. You will have to useDateOfwhenever you receive a date value, and clearly before you add to the dictionary.