From 64c324caafe8907f888f19fdbc720da24670e80c Mon Sep 17 00:00:00 2001 From: michael Date: Fri, 15 Jan 2016 07:48:49 +0000 Subject: [PATCH] * Patch from Silvio Clecio to add a TryGetValue method to TFPGMap (bug ID 29397) git-svn-id: trunk@32942 - --- rtl/objpas/fgl.pp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/rtl/objpas/fgl.pp b/rtl/objpas/fgl.pp index 39e867a381..a926e8959e 100644 --- a/rtl/objpas/fgl.pp +++ b/rtl/objpas/fgl.pp @@ -305,6 +305,7 @@ type function Add(const AKey: TKey; const AData: TData): Integer; {$ifdef CLASSESINLINE} inline; {$endif} function Add(const AKey: TKey): Integer; {$ifdef CLASSESINLINE} inline; {$endif} function Find(const AKey: TKey; out Index: Integer): Boolean; {$ifdef CLASSESINLINE} inline; {$endif} + function TryGetValue(const AKey: TKey; out AData: TData): Boolean; {$ifdef CLASSESINLINE} inline; {$endif} function IndexOf(const AKey: TKey): Integer; {$ifdef CLASSESINLINE} inline; {$endif} function IndexOfData(const AData: TData): Integer; procedure InsertKey(Index: Integer; const AKey: TKey); @@ -1481,6 +1482,17 @@ begin Result := inherited Find(@AKey, Index); end; +function TFPGMap.TryGetValue(const AKey: TKey; out AData: TData): Boolean; +var + I: Integer; +begin + Result := inherited Find(@AKey, I); + if Result then + AData := TData(inherited GetData(I)^) + else + AData := Default(TData); +end; + function TFPGMap.IndexOf(const AKey: TKey): Integer; begin Result := inherited IndexOf(@AKey);