[comp.windows.interviews] Problem in StringBrowser

janc@HPLDS3.SID.HP.COM (Jan Chang) (04/30/91)

   Environment: 
     IV2.6 on HP800 running C++ 2.1 
  OR IV2.6 on HP300 running C++ 2.0 

   Several of us in my division had the similar problem as follows:
using a multiple selections stringbrowser, we need to remove 
all the selected strings from one stringbrowser and insert them into 
another stringbrowser (or the same one) one by one.  The problem is 
from time to time we are getting garbage in the destination 
stringbrowser.  We suspect that it might be  memory corruption 
somewhere and have tried different ways to store the string returned 
from String(), but doesn't help.  Could anyone tell me what is the  
problem?

Thanks,
Jan

//Code to do the Removing and Inserting in a loop
// In this case, we are using only one stringbrowser.
void TestStsBrowser::ChangeStatus(char* newStsValue) 
{
   char *str;
   int index ;
   char *tmpstr;

   // Get number of strings being selected
   int count = _sts_sbr->Selections();

   for (int i = 0; i < count; ++i) 
   {
      index = _sts_sbr->Selection();
      str = _sts_sbr->String(index);

      tmpstr = new char[strlen((char*)str) + 1];
      strcpy (tmpstr, (char*)str);
      // Remove string from the browser
      _sts_sbr->Remove(index);
      
      // Insert string to the same index
      _sts_sbr->Insert((const char*)tmpstr, index);

   }
}