Ich würde es mal als Bug definieren und diesen gibt es immernoch im XE3.
Am Besten solltest du mal im
QC 'ne Meldung einreichen. (falls es nicht schon Eine gibt)
Das Problem ist nicht direkt der Variant, sondern der Weert, welchen du übergibst.
Vorallem scheint es da mit Typen ein Problem zu geben, welche der Variant standardmäßig selbst nicht unterstützt.
Zitat:
Delphi-Quellcode:
// The data represented by a variant come in three flavors.
//1) 'Inline data variant' is one whose data doesn't have to be allocated
// and is actually contained within the payload area of the variant.
// Since the data wasn't allocated, it doesn't have to be deallocated.
// So to clear this type of variant we simply need to change it's VarType
// to varEmpty. Some examples of this type of variant include:
// varInteger, varDouble, varDate, etc.
//2) 'External data variant' is one whose data has to be allocated. The
// payload area of the variant only contains a reference to the allocated
// data. But since we allocated the data we are responsible for
// deallocating it. So to clear this type of variant we have to do more
// than simply set it's VarType to varEmpty, the referenced data must
// also be deallocated. Some examples of this type of variant include:
// varString, varOleStr, varDispatch, varArray, etc.
//3) 'By ref data' is a variant that simply points to externally managed
// data. Since the data is managed by someone else we don't have to
// deallocate the data when clearing this type of variant, we can simply
// set the VarType to varEmpty. This type of variant's VarType will also
// reflect the referenced data's VarType.
//To quickly determine what we need to do for a certain VarType we have
//created the following mask value. When 'AND'ed with the VarType of a
//variant we can quickly determine which of the above three variant data
//types is being cleared. This value is not perfect but there are only two
//cases where it gets it wrong (varBoolean and varError) and those are
//quickly dealt with when they come up.
varDeepData = $BFE8;
varDeepData ist der Typ, welchen dein True-Wert intern besitzt.
Beim Auslesen und Übersetzen dieses Wertes gibt es dann den Fehler.
RTTI.TValue kann dadurch der Wert nicht zugewiesen werden. (System._VarCopy schlägt fehl)
Du kannst es gerne mal mit
[MyDefaultAttr(2)]
versuchen.
[MyDefaultAttr(Integer(2))]
funktioniert aber.
Leider funktioniert das Casten nach Boolean/ByteBool/WordBool/LongBool nicht. (wobei Variant den WordBool eigentlich kennt)