I do not experience general collections. I need to sort a TDictionary.
type TSearchResult = TPair<Integer,double>; var target_results : TDictionary<Integer, double>; session_search_results : array[0..max_searches] of TArray<TSearchResult>;
I sort using this code
session_search_results[session_search_id]:= target_results.ToArray; TArray.Sort<TSearchResult>(session_search_results[session_search_id], TComparer<TSearchResult>.Construct( function(const L, R: TSearchResult): Integer begin Result := Round(R.Value - L.Value); end ));
Why am I getting an access violation with this? What am I doing wrong?
complement:
If I iterate over an array using
for i:= 0 to Length(session_search_results[session_search_id])-1 do MyDebug(IntToStr(session_search_results[session_search_id][i].Key)+' = value = ' + FloatToStr(session_search_results[session_search_id][i].Value));
I get the output:
Debug Output: ==>CoreSearchText: array length=8<== Process TestApp.exe (2536) Debug Output: ==>100007 = value = 19,515<== Process TestApp.exe (2536) Debug Output: ==>100003 = value = 2,4<== Process TestApp.exe (2536) Debug Output: ==>100005 = value = 12<== Process TestApp.exe (2536) Debug Output: ==>100008 = value = 2,4<== Process TestApp.exe (2536) Debug Output: ==>100002 = value = 2,4<== Process TestApp.exe (2536) Debug Output: ==>100004 = value = 2,4<== Process TestApp.exe (2536) Debug Output: ==>100009 = value = 40,515<== Process TestApp.exe (2536) Debug Output: ==>100001 = value = 15<== Process TestApp.exe (2536)
Using sorting Access violation violates the application. The array seems to be in order. What is the reason? Thanks!
source share