I have a dictionary crash in the DataSnap client because its FComparer is somehow nil.
Server side code:
TColorNames = TDictionary<integer, string>;
function TServerMethods.DictionaryTest: TColorNames;
begin
result := TColorNames.Create;
result.Add (1, 'Red');
result.Add (2, 'Blue');
end;
Client side code:
procedure TformClientMain.FetchColors;
var
Colors: TColorNames;
begin
Colors := easServer.DictionaryTest;
if Colors.Items[1]<>'Red'
then ShowMessage('Not red');
end;
Colors.Items[1]
crashes (as well as other functions that need the FComparer). The crash happens in System.Generics.Collections, when the function tries to access the FComparer.
function TDictionary<TKey,TValue>.Hash(const Key: TKey): Integer;
I do receive all the data in the list, and just looping through it with for color in Colors.Values do ShowMessage(Color);
works fine.
When I create a dictionary instance with TColorNames.Create, on client or server side, the FComparer has a value and these issues do not exist. I placed breakpoints in the dictionary constructor and traced the code during the datasnap call - FComparer always gets a value.
What am I (or Delphi) doing wrong?