Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   XML (https://www.delphipraxis.net/46-xml/)
-   -   Set als Attribut in xml File speichern (https://www.delphipraxis.net/165640-set-als-attribut-xml-file-speichern.html)

runner 9. Jan 2012 22:34

Set als Attribut in xml File speichern
 
Hallo zusammen,

steh grade ein bisschen auf dem Schlauch. Mein Problem ist das ich ein Set in der Art

Delphi-Quellcode:
TPointState = set of (psUnknown, psNormal, psPaused, psDeleted, psInsert ...);


als Attribut in einem xml File speichern will. Das speichern von TPointState geht natürlich nicht direkt. Muss ich das Set eineln zerpflücken oder gibt es eine elegantere Methode hierfür?

s.h.a.r.k 9. Jan 2012 22:51

AW: Set als Attribut in xml File speichern
 
Du kannst das Ding als Byte speichern, da ein Enum nichts anderes als ein Byte ist, ebenso eine Menge.
Delphi-Quellcode:
var
  EnumValue : TPointState ;
  ByteValue : Byte;
begin
  EnumValue := [];
  ByteValue := Byte(EnumValue);
  // ByteValue = 0;
end;
PS: Du kannst auch die SetToString-Methode aus der Unit TypInfo nutzen.
Delphi-Quellcode:
var
  TI : PTypeInfo;
  PS : TPointState;
begin
  TI := TypeInfo(TPointState);
  Writeln(SetToString(TI, Byte(PS), True));
end;

runner 10. Jan 2012 06:18

AW: Set als Attribut in xml File speichern
 
Hallo s.h.a.r.k,

so einfach können Lösungen sein...

Danke für die Hilfe

Codewalker 10. Jan 2012 08:19

AW: Set als Attribut in xml File speichern
 
Zitat:

Zitat von s.h.a.r.k (Beitrag 1145146)
PS: Du kannst auch die SetToString-Methode aus der Unit TypInfo nutzen.

Wobei man mit den TypInfos böse auf die Nase fallen kann: Wenn man den einzelnen Werten manuell Zahlen zuordnet
Delphi-Quellcode:
TPointState = set of (psUnknown = 0, psNormal = 1, psPaused = 12, psDeleted = 42, psInsert = 50 ...);
, so bekommt das Set (warum auch immer) keine TypeInfos mehr und man kann es auf diese Weise nicht ermitteln (Danke nochmal an himitsu, der mir da echt graue Haare erspaart hat).


Alle Zeitangaben in WEZ +1. Es ist jetzt 11:11 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz