tdictionary

Sorting TDictionary by a key of Integer in ascending order

一曲冷凌霜 提交于 2020-06-10 11:15:57
问题 How can I sort TDictionary by a key of Integer in ascending order in Delphi 2009? 回答1: The RTL TDictionaries are not sorted and cannot be sorted (other than by hash, which they are). You need to use another container if you wish to sort either the keys or the values. For example : program Project1; {$APPTYPE CONSOLE} uses Generics.Collections, Generics.Defaults, SysUtils; var LDict : TDictionary<integer, string>; i, j : integer; LArray : TArray<integer>; begin LDict := TDictionary<integer,

Sorting TDictionary by a key of Integer in ascending order

我与影子孤独终老i 提交于 2020-06-10 11:15:47
问题 How can I sort TDictionary by a key of Integer in ascending order in Delphi 2009? 回答1: The RTL TDictionaries are not sorted and cannot be sorted (other than by hash, which they are). You need to use another container if you wish to sort either the keys or the values. For example : program Project1; {$APPTYPE CONSOLE} uses Generics.Collections, Generics.Defaults, SysUtils; var LDict : TDictionary<integer, string>; i, j : integer; LArray : TArray<integer>; begin LDict := TDictionary<integer,

TDictionary save to file

我的梦境 提交于 2019-12-29 07:11:50
问题 I have a lot of files(about 160 000) and I need to have information about position of individual words in files(fulltext). So I used Dictionary like this: WordDict : TDictionary<string, TDictionary<string, TIntegerDynArray>>; Now I know that WORD1 is in FILE1,FILE3 and FILE100 and positions in each file <1,3,5>,<2,8,35> etc. I can fill it, I can use it - its very fast. But I don't know how effectively store dictionary to file. EDIT: effectively - I mean quickly and small size of file 回答1: You

delphi dictionary iterating

孤人 提交于 2019-12-13 18:08:23
问题 g'morning! i fill a dictionary TDictionary<String, TStringlist> (delphi-collections-unit) with strings as values and several strings as values. something like: names = john, lisa, stan skills = read, write, speak ages = 12, 14, 16 (without "," of course). what i need is to iterate this dictionary and to multiply out the values with the keys. output should be like names = john skills = read ages = 12 names = john skills = read ages = 14 names = john skills = read ages = 16 names = john skills

GetItem on TDictionary eleminated by linker

我的未来我决定 提交于 2019-12-10 10:38:13
问题 I am using a TDictionary of <string, string> . But for some reason, the linker decides that I do not want to get items out of it. I have the following code: function TSheet.GetFieldName(Field: string; Default: string): string; begin Result := Default; if FFieldNames[Field] = '' then Result := Field else Result := FFieldNames[Field]; end; FFieldNames is a TDictionary<string, string> . On line 2 ( if FFieldNames[Field] = '' then ), it throws a 'File not found' exception. Adding FFieldNames

Why does a deserialized TDictionary not work correctly?

不问归期 提交于 2019-12-08 19:28:30
问题 I try serialize/deserialize standard delphi container using standard delphi serializer. procedure TForm7.TestButtonClick(Sender: TObject); var dict: TDictionary<Integer, Integer>; jsonValue: TJSONValue; begin //serialization dict := TDictionary<Integer, Integer>.Create; dict.Add(1, 1); jsonValue := TJsonConverter.ObjectToJSON(dict); dict.Free; //deserialization dict := TJsonConverter.JSONToObject(jsonValue) as TDictionary<Integer, Integer>; try Assert(dict.ContainsKey(1), 'deserialization

GetItem on TDictionary eleminated by linker

ε祈祈猫儿з 提交于 2019-12-06 09:28:36
I am using a TDictionary of <string, string> . But for some reason, the linker decides that I do not want to get items out of it. I have the following code: function TSheet.GetFieldName(Field: string; Default: string): string; begin Result := Default; if FFieldNames[Field] = '' then Result := Field else Result := FFieldNames[Field]; end; FFieldNames is a TDictionary<string, string> . On line 2 ( if FFieldNames[Field] = '' then ), it throws a 'File not found' exception. Adding FFieldNames[Field] to my watch tells me that Function to be called, {System.Generics.Collections}TDictionary.GetItem,

delphi Using records as key in TDictionary

会有一股神秘感。 提交于 2019-12-03 11:39:36
问题 Can you use a record as a Key value in TDictionary? I want to find objects based on combination of string, integer and integer. TUserParKey=record App:string; ID:integer; Nr:integer; end; ... var tmpKey:TUserParKey; tmpObject:TObject; begin tmpObject:= TTObject.Create(1); tmpKey.App:='1'; tmpKey.ID :=1; tmpKey.Nr :=1; DTUserPars.Add(tmpKey,tmpObject) ... var tmpKey:TUserParKey; begin tmpKey.App:='1'; tmpKey.ID :=1; tmpKey.Nr :=1; if not DTUserPars.TryGetValue(tmpKey,Result) then begin result