Thursday, February 3, 2011

Numerical attributes in XML & no value in code

I know it's a stupid case, but sometimes I forgot about simple things.

Problem:
we have numerical value in XML like:

<component itemHeight="20" itemsVSpace="10" .../>

in code we want to use those values

itemLabel.y = index*( _contentXML.@itemHeight + _contentXML.@itemsVSpace);

Result? We receive zero. Because attribute value is used as String and + works as concatenation. Then multiple converts value to zero. We have to cast values at the begining to expected type:

itemLabel.y = index*( int(_contentXML.@itemHeight) + int(_contentXML.@itemsVSpace) );

No comments:

Post a Comment