相关疑难解决方法(0)

Delphi字典和订购数据

我的代码是:

procedure TfrmSettings.btnFillDictClick(Sender: TObject);
var
  Dict: TDictionary<string, string>;
  Item: TPair<string, string>;
begin
  Dict := TDictionary<string, string>.Create();

  Dict.Add('Key1', 'Text1');
  Dict.Add('Key2', 'Text2');
  Dict.Add('Key3', 'Text3');
  Dict.Add('Key4', 'Text4');

  for Item in Dict do
  begin
    ShowMessage(Item.Key + ' ' + Item.Value);
  end;    
end;
Run Code Online (Sandbox Code Playgroud)

为什么几乎每次我在Showmessage中获得不同的价值?
为什么值不按添加顺序存储?

我是Delphi的菜鸟,不知道Dictionary是如何运作的.我在谷歌没有找到任何相关信息.你能解释一下为什么会这样吗?
有没有办法使用Dictionary而不使用TList <>进行排序数据?

谢谢

delphi dictionary delphi-xe

4
推荐指数
1
解决办法
1528
查看次数

标签 统计

delphi ×1

delphi-xe ×1

dictionary ×1