I have the following code with two dictionaries. I can see that when I iterate through DictForbidden even though it is empty the execution flow enters the loop so DictToAdd.remove(anInteger); is executed with the old value of anInteger
var DictForbidden, DictToAdd : TDictionary<Integer,boolean>;
var anInteger: Integer;
DictForbidden := TDictionary<Integer,boolean>.Create;
DictToAdd := TDictionary<Integer,boolean>.Create;
anInteger := 1;
DictToAdd.Add(anInteger,true);
for anInteger in DictForbidden.Keys do
DictToAdd.remove(anInteger);
DictForbidden.Free;
DictToAdd.Free;
I am running Delphi 10.4 and I don't recall such a behavior in 10.3. I think back then if the dictionary was empty the loop was not entered. Do you know if this is something new on Delphi 10.4?, or maybe I am doing something wrong here?
regards, Carlos

