![]() |
TDictionary problem mit Types
Die Types
Delphi-Quellcode:
Ich definiere die Procedure so.
TDeviceIcon = (DesktopMicrophone, Digital, Headphones, Headset,
Kinect, LineIn, Phone, Speakers, StereoMix, Monitor, Unknown); TIndex = string; TIconMap = TDictionary<TDeviceIcon, TIndex>; Warum wird dann der Type DeviceIcon ignoriert bzw.. es wird ein Fehler gemeldet.
Delphi-Quellcode:
Nach meinem Verständnis sollte das eigentlich OK sein aber der Compiler will unbedingt TDeviceIcon, TIndex.
procedure TAudioVolume.Dictionary(Index: TIndex; DeviceIcon: TDeviceIcon);
var IconMap: TDictionary<DeviceIcon, Index>; Das schlägt also fehl..
Delphi-Quellcode:
Auch das hier!
IconMap := TDictionary<DeviceIcon, Index>.Create();
IconMap.Add(DeviceIcon.Speakers, '0'); IconMap.Add(DeviceIcon.Speakers, '1');
Delphi-Quellcode:
IconMap.Add(DeviceIcon.Speakers, '1');
Aber ich brauche diesen Eintrag mehrmals.. Deshalb weil das Icon mehrmals in der Ressource vorhanden ist. RESSOURCENNAME 3004 RESSOURCENNAME 3010 RESSOURCENNAME 3019 RESSOURCENNAME 3030 RESSOURCENNAME 3050 Ich muss jedem einzelnen den Type DeviceIcon.Speakers zuweisen. gruss |
AW: TDictionary problem mit Types
Zitat:
|
AW: TDictionary problem mit Types
Zitat:
Delphi-Quellcode:
vergessen.
T
Delphi-Quellcode:
bzw. da du dir ja schon einen Typ definiert hast, am besten:
procedure TAudioVolume.Dictionary(Index: TIndex; DeviceIcon: TDeviceIcon);
var IconMap: TDictionary<DeviceIcon, TIndex>; // <-- TIndex statt Index
Delphi-Quellcode:
procedure TAudioVolume.Dictionary(Index: TIndex; DeviceIcon: TDeviceIcon);
var IconMap: TIconMap; |
AW: TDictionary problem mit Types
Zitat:
Denn Index ist als TIndex definiert. Welchen sinn macht eine definition wenn sie nicht verwendet wird? Das ist ja mein Problem und unverständlich für mich.
Delphi-Quellcode:
in der Procedure.
Index: TIndex;
Das müsste dann so aussehen
Delphi-Quellcode:
Oder?
IconMap.Add(DeviceIcon.Speakers, '0');
IconMap.Add(DeviceIcon.Speakers, Index('0')); gruss |
AW: TDictionary problem mit Types
Doch doch, du hast da grade einen Denkfehler. Dein Typ ist eben
Delphi-Quellcode:
(mit
TIndex
Delphi-Quellcode:
). Und die Deklaration der Variable
T
Delphi-Quellcode:
erfordert nun eben einen generischen Typ und keine konkrete (Variablen-)Instanz - in deinem Falle
IconMap
Delphi-Quellcode:
(ohne
Index
Delphi-Quellcode:
) - vom entsprechenden Typ (ist so bisschen wie der Vergleich Klasse vs. Objekt(instanz)). Weiter unten die Versuche mit
T
Delphi-Quellcode:
sind korrekt und sollten auch funktionieren, wenn du die von mir oben beschriebenen Änderungen durchführst.
IconMap.Add(DeviceIcon.Speakers, '0')
|
AW: TDictionary problem mit Types
Zitat:
Aber es kracht wenn ich zweimal den gleichen Aufruf verwende.
Delphi-Quellcode:
beim 2.ten
IconMap.Add(DeviceIcon.Speakers, '0');
IconMap.Add(DeviceIcon.Speakers, '1'); Hoffe mal nach der Änderung nicht mehr. Und was mache ich dann mit dem TIndex? irgendwie sinnlos.. Hmmm gruss |
AW: TDictionary problem mit Types
Zitat:
Delphi-Quellcode:
ist eine flache Map, deshalb darf jeder Key (also dein
TDictionary
Delphi-Quellcode:
Wert) darin nur einmal vorkommen. Was du suchst ist eine
TDeviceIcon
Delphi-Quellcode:
. Oder alternativ natürlich auch
TList<TPair<TDeviceIcon, TIndex>>
Delphi-Quellcode:
. Wenn du eher wenige Einträge hast, nimm die Liste (ist einfacher).
TDictionary<TDeviceIcon, TArray/TList<TIndex>>
|
AW: TDictionary problem mit Types
Hmmm.. nicht so einfach der Kram mit Generics.. ;)
Werde es mal testen. Vielleicht reicht auch eine ganz einfache TStringlist. Ich glaube ich lasse es zu viel ärger. ;) DAnke. gruss |
AW: TDictionary problem mit Types
Zitat:
|
AW: TDictionary problem mit Types
Zitat:
Egal hat sich erledigt! Habe es auf anderer weise geregelt und funktioniert nun alles. gruss |
AW: TDictionary problem mit Types
|
AW: TDictionary problem mit Types
Zitat:
Zitat:
gruss |
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:51 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-2025 by Thomas Breitkreuz