* More routines need to display missing key name

This commit is contained in:
Michaël Van Canneyt 2024-05-15 08:21:32 +02:00
parent 4a4eadc60e
commit fc29d5ca7d
3 changed files with 18 additions and 4 deletions

View File

@ -3506,7 +3506,7 @@ begin
if not Assigned(LNode) then
begin
K:=aKey;
TValue.Make(@K,TypeInfo(TKey),D);
{$IFDEF FPC_DOTTEDUNITS}System.{$ENDIF}Rtti.TValue.Make(@K,TypeInfo(TKey),D);
raise EAVLTree.CreateFmt(SDictionaryKeyNNNDoesNotExist,[D.ToString]);
end;
result := LNode.Value;

View File

@ -31,7 +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';
SDictionaryKeyNNNDoesNotExist = 'Dictionary key "%s" does not exist';
SItemNotFound = 'Item not found';
implementation

View File

@ -571,10 +571,17 @@ end;
function TOpenAddressing<OPEN_ADDRESSING_CONSTRAINTS>.GetItem(const AKey: TKey): TValue;
var
LIndex: SizeInt;
D : {$IFDEF FPC_DOTTEDUNITS}System.{$ENDIF}Rtti.TValue;
K : TKey;
begin
LIndex := FindBucketIndex(AKey);
if LIndex < 0 then
raise EListError.CreateRes(@SDictionaryKeyDoesNotExist);
begin
K:=aKey;
{$IFDEF FPC_DOTTEDUNITS}System.{$ENDIF}Rtti.TValue.Make(@K,TypeInfo(TKey),D);
raise EListError.CreateFmt(SDictionaryKeyNNNDoesNotExist,[D.ToString]);
end;
Result := FItems[LIndex].Pair.Value;
end;
@ -1993,6 +2000,9 @@ var
LHashListOrIndex: PUint32;
LLookupResult: SizeInt;
LIndex: UInt32;
D : {$IFDEF FPC_DOTTEDUNITS}System.{$ENDIF}Rtti.TValue;
K : TKey;
begin
LHashListOrIndex := @LHashList[0];
LLookupResult := Lookup(AKey, LHashListOrIndex);
@ -2001,7 +2011,11 @@ begin
LR_QUEUE:
Result := FQueue.FItems[PtrInt(LHashListOrIndex)].Pair.Value.Pair.Value;
LR_NIL:
raise EListError.CreateRes(@SDictionaryKeyDoesNotExist);
begin
K:=aKey;
{$IFDEF FPC_DOTTEDUNITS}System.{$ENDIF}Rtti.TValue.Make(@K,TypeInfo(TKey),D);
raise EListError.CreateFmt(SDictionaryKeyNNNDoesNotExist,[D.ToString]);
end;
else
LIndex := LHashListOrIndex[LLookupResult + 1] and (Length(FItems[0]) - 1);
Result := FItems[LLookupResult][LIndex].Pair.Value;