GetUserPropString mangles my MSTR.

GetUserPropString mangles my MSTR.

Anonymous
Not applicable
455 Views
5 Replies
Message 1 of 6

GetUserPropString mangles my MSTR.

Anonymous
Not applicable
What is the best way to deal with Object Properties that have a blank data portions.
I am getting bad results if a Key exists and there is no data present. See below.


void myClass::GetSomeInfo(INode* pointerToNode)
{
MSTR my_BadString;
MSTR my_GoodString;

pointerToNode->GetUserPropString("keyWithData", my_GoodString);
pointerToNode->GetUserPropString("keyNoData", my_BadString);


myClass::FillStringWithData(my_GoodString);
myClass::FillStringWithData(my_BadString);

}


If a Key exists in the object properties such as below then my_BadString becomes corrupt, and I cannot fill it with data or even test if the my_BadString.data() is NULL or pretty much anything and the my_BadString becomes a bad pointer.

Object Properties =
{

keyWithData = greatThisWorksBecauseThereIsData
keyNoData =

}
0 Likes
456 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
From 2011 SDK help:
BOOL INode::GetUserPropString(...)
Returns:
TRUE if the key was found; otherwise FALSE.

Just test return value of GetUserPropString first.
0 Likes
Message 3 of 6

Anonymous
Not applicable
Wow at first glance I thought that I had had a bit of a dumb moment and that the answer would be that simple.

The problem is a bit harder then that though as GetUserPropString(..) will return TRUE if the Key is there, (as is the case above) but the associated value is not. ie the function returns TRUE regardless of the presence of the VALUE portion of the KEY VALUE pair as long as the KEY is there.

Perhaps I will just assume that the Key Value pair is always complete / well formed. There is just potential for the data to be altered by a user and for that alteration to be an empty string.
0 Likes
Message 4 of 6

Anonymous
Not applicable
Well, I can't say I have experience in this area, so I'm kind of guessing. Yet, have you tested my_BadString method isNull() ?
Anyway, what is your intention with FillStringWithData? Name would suggest you'd need reference to string rather than a copy.
0 Likes
Message 5 of 6

Anonymous
Not applicable
Ok, the solution is to Resize() the buffer after checking for IsNull(). When I just tried to fill the buffer without the resize nothing would be saved I guess because there was no room for my string.

I did try a comparison with null previously but that was checking if the pointer was null not the string.

Cheers, Jake.
0 Likes
Message 6 of 6

Anonymous
Not applicable
Yeap, string handling might be a bit tricky. I'm glad, if I could be helpful.
0 Likes