* When raising error, display missing key value as string, if possible

This commit is contained in:
Michaël Van Canneyt 2024-05-14 08:58:39 +02:00
parent 291532e740
commit 259af2d252
2 changed files with 14 additions and 3 deletions

View File

@ -46,11 +46,11 @@ interface
{$IFDEF FPC_DOTTEDUNITS}
uses
System.RtlConsts, System.Classes, System.SysUtils, System.Generics.MemoryExpanders, System.Generics.Defaults,
System.Generics.Helpers, System.Generics.Strings, System.Types;
System.Generics.Helpers, System.Generics.Strings, System.Types, System.Rtti;
{$ELSE FPC_DOTTEDUNITS}
uses
RtlConsts, Classes, SysUtils, Generics.MemoryExpanders, Generics.Defaults,
Generics.Helpers, Generics.Strings, Types;
Generics.Helpers, Generics.Strings, Types, Rtti;
{$ENDIF FPC_DOTTEDUNITS}
{.$define EXTRA_WARNINGS}
@ -3492,13 +3492,23 @@ begin
Result := TValueCollection(FValues);
end;
function TCustomAVLTreeMap<TREE_CONSTRAINTS>.GetItem(const AKey: TKey): TValue;
var
LNode: PNode;
// Need to differentiate with TValue template type...
D : {$IFDEF FPC_DOTTEDUNITS}System.{$ENDIF}Rtti.TValue;
K : TKey;
begin
LNode := Find(AKey);
if not Assigned(LNode) then
raise EAVLTree.CreateRes(@SDictionaryKeyDoesNotExist);
begin
K:=aKey;
TValue.Make(@K,TypeInfo(TKey),D);
raise EAVLTree.CreateFmt(SDictionaryKeyNNNDoesNotExist,[D.ToString]);
end;
result := LNode.Value;
end;

View File

@ -31,6 +31,7 @@ resourcestring
SCollectionInconsistency = 'Collection inconsistency';
SCollectionDuplicate = 'Collection does not allow duplicates';
SDictionaryKeyDoesNotExist = 'Dictionary key does not exist';
SDictionaryKeyNNNDoesNotExist = 'Dictionary key %s does not exist';
SItemNotFound = 'Item not found';
implementation