--- siddharth saxena <[EMAIL PROTECTED]> wrote:
> i.e."bus error" and "address error".sometime  it gives
> errors like"the application just wrote to an
> unallocated chunk of memory"
<snip>

I think you are trying to save the text of a field into a filestream,
then write that text back to that field.  However, your code has
several logic errors (e.g., closing the filestream inside the while
loop that is reading from the filestream, using a buffer that can only
hold 2 chars, inserting 1 char at a time into the field, etc.).

Here is some code, similar to yours but functional, that you can use. 
I'm not sure what you will be able to learn from it.  (Note: this is
not optimal code; it's just the closest thing I could get to what you
started with that works.)

// copy text from MainFieldField to a filestream
static void doSaveButton(void)
{
  Err err;
  Char *textp;
  FieldType *fldp;
  UInt16 objindex;
  FileHand streamsave;
  FormType *frmp;

  // get the field's text       
  frmp = FrmGetFormPtr( MainForm );
  objindex = FrmGetObjectIndex( frmp, MainFieldField );
  fldp = FrmGetObjectPtr( frmp, objindex );
  textp = FldGetTextPtr( fldp );

  if ( textp )
  {
    // open/create file stream
    streamsave = FileOpen( 0, filename, filetype, 
        filecreator, fileModeAppend, &err );
    if ( streamsave && (!err) )
    {
      // write field's text to file stream
      FileWrite( streamsave, textp, StrLen(textp)+1, 1, NULL);
      FileClose( streamsave );
    }
  }
}

// read a filestream and insert it into MainFieldField
static void doShowButton(void)
{
  Err err;
  Char buffer[100], *p;  // however big MainFieldField is
  FileHand streamshow;
  FieldType *fldp;
  UInt16 objindex;
  FormType *frmp;
  Int32 count;

  // get field pointer
  frmp = FrmGetFormPtr( MainForm );
  objindex = FrmGetObjectIndex( frmp, MainFieldField );
  fldp = FrmGetObjectPtr( frmp, objindex );

  // open file stream                   
  streamshow = FileOpen( 0, filename, filetype, 
          filecreator, fileModeReadOnly, &err );

  if ( streamshow && (!err) )
  {
    // read file stream 1 byte at a time
    p = buffer;
    while(! FileEOF(streamshow))
    {
      count = FileRead( streamshow, p, sizeof(Char), 1, NULL );
      p++;
    }
    FileClose( streamshow );

    // insert text from file stream into field
    FldInsert( fldp, buffer, StrLen(buffer) );
  }
}

PS: You don't need to put my name in the subject line.  Anybody who
wants to answer your questions can do so.


__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/

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

Reply via email to