Hello!

I've written a chunk of code that displays some text on the screen. I've
declared a gadget where the text will be displayed. However, whenever the
text is copied using StrCopy, I'll always get a "bus error". Can someone
help me?

static void PrintOnScreen(const CharPtr text)
{
 Int16    lineHeight;
 Int16    strLength;
 Int16    gadgetWidth;
 Boolean   canFit;
 Word    objIndex;
 RectangleType bounds;
 CharPtr   tempText1;
 CharPtr   tempText2;
 FormPtr   frm;

 // init variables
 FntSetFont (stdFont);
 lineHeight = FntLineHeight();
 strLength = StrLen(text);

 // get the bounds of the text window
 frm = FrmGetActiveForm();
 objIndex = FrmGetObjectIndex (frm, MainTextWindowGadget);
 FrmGetObjectBounds (frm, objIndex, &bounds);
 gadgetWidth = bounds.extent.x;

 FntCharsInWidth (text, &gadgetWidth, &strLength, &canFit);
   if (canFit)
   {
      CheckScrolling (bounds, lineHeight); // make sure got space for 1 line
      WinDrawChars (text, strLength, 0, CurrentYPos);
      CurrentYPos += lineHeight;
   }
   else
 {
  tempText2 = "";

*********** Problem lies here ***********
  StrCopy (tempText1, text);
  StrNCopy (tempText2, text, strLength);  // copy string that fits
*********** Problem lies here ***********

  CheckScrolling (bounds, lineHeight);
  WinDrawChars (tempText2, strLength, 0, CurrentYPos);
  CurrentYPos += lineHeight;

  do {
   // now we get the rest of the string
   tempText1 += strLength;

   // init variables and determine whether rest of string fits
   strLength = StrLen (tempText1);
   gadgetWidth = bounds.extent.x;
   FntCharsInWidth (tempText1, &gadgetWidth, &strLength, &canFit);

   // copy string (regardless of fit or not)
   StrNCopy (tempText2, tempText1, strLength);

   CheckScrolling (&bounds, lineHeight);
   WinDrawChars (tempText2, strLength, 0, CurrentYPos);
   CurrentYPos += lineHeight;

  } while (!canFit); // loop until rest of string fits
 }
}




-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to