String to tchar / getStringAttribute((String)attribname)how?


#1

hi,
i try to get an XML attribute with a variable attribute name.
like this:

void SomeClass::fillList(ComboBox* box,String fieldName)
{
box->addItem(someXmlData->getStringAttribute(fieldName));
}

getStringAttribute wants “const tchar *const attributeName” of course, but how to convert to this from String? i don’t get it.

thanks

D3CK


#2

The easiest ways is just to wrap the String in a T() macro,

I.E. instead of “hello” use T(“hello”)


#3

thanks
but using literals does not help here.
:wink:
D3CK


#4

Well, a string will readily produce a Tchar type. Is it just a cast to const you need?

Bruce


#5

ahh! I’m a bit shy with type casts when not using my own classes.
so:

String cat;
String text = someXmlData->getStringAttribute((const tchar*)cat);

seems to work so far.
thanks a lot!
:smiley:
D3CK


#6

There’s no need to explicitly use that (const tchar*) cast there, the compiler will handle it for you.