AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

TDictionary mit zusammengesetztem Schlüssel

Ein Thema von TurboMagic · begonnen am 5. Nov 2024 · letzter Beitrag vom 6. Nov 2024
 
TurboMagic

Registriert seit: 28. Feb 2016
Ort: Nordost Baden-Württemberg
3.029 Beiträge
 
Delphi 12 Athens
 
#1

TDictionary mit zusammengesetztem Schlüssel

  Alt 5. Nov 2024, 20:39
Hallo,

irgendwo biege ich falsch ab...

Delphi-Quellcode:
type
  TStatisticsKey = record
    ProductID : Integer;
    ConsumptionPlace : TConsumptionPlace;
  end;


function TStatisticsProductDict.IncSubID(ProductID : Integer;
                                         ConsumptionPlace : TConsumptionPlace): Integer;
var
  Key : TStatisticsKey;
  Pair : TPair<TStatisticsKey, Integer>;
begin
  Key.ProductID := ProductID;
  Key.ConsumptionPlace := ConsumptionPlace;

  if FItems.ContainsKey(Key) then
  begin
    Pair := FItems.ExtractPair(Key);
    Result := Pair.Value + 1;

    FItems.Add(Key, Result);
  end
  else
  begin
    FItems.Add(Key, 0);
    Result := 0;
  end;
end;
FItems ist ein TDictionary<TStatisticsKey, Integer>
Das Problem ist jetzt, dass beim ersten Aufruf zwar ein Eintrag zu FItems hinzugefügt wird,
beim nächsten Aufruf mit genau der selben ProductID und Consumption Place findet ContainsKey
diesen nicht und fügt daher einen weiteren Eintrag mit dem Schlüssel hinzu.

Was mache ich falsch?
Grüße
TurboMagic
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 08:47 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz