> From: Cynon Mac an Choile
>
>    I have been trying to write a very simple program.  And I've met
> with a large amount of difficulty which leads me to believe that I am
> doing something very wrong.
>

You didn't say exactly what the problem was.  But here is a real simple
example that writes 3 strings to a database:

// global var for the db
DmOpenRef gDB;

static void AddThreeStrings( void )
// Add three records to the db, each containing one string
// (too lazy to add error checking)
{
  MemHandle recHandle;
  MemPtr recPtr;
  UInt16 location;

  Char * m1 = "one";
  Char * m2 = "two";
  Char * m3 = "three";

  location = DmNumRecords(gDB); // 0
  recHandle = DmNewRecord(gDB, &location, StrLen(m1)+1 );
  recPtr = MemHandleLock(recHandle);
  DmWrite(recPtr, 0, m1, StrLen(m1)+1);
  MemHandleUnlock(recHandle);

  location = DmNumRecords(gDB); // 1
  recHandle = DmNewRecord(gDB, &location, StrLen(m2)+1);
  recPtr = MemHandleLock(recHandle);
  DmWrite(recPtr, 0, m2, StrLen(m2)+1);
  MemHandleUnlock(recHandle);

  location = DmNumRecords(gDB); // 2
  recHandle = DmNewRecord(gDB, &location, StrLen(m3)+1);
  recPtr = MemHandleLock(recHandle);
  DmWrite(recPtr, 0, m3, StrLen(m3)+1);
  MemHandleUnlock(recHandle);
}

static Err AppStart(void)
{
  Err err;

  // open the db
  gDB = DmOpenDatabaseByTypeCreator('Data', 'STRT', dmModeReadWrite);
  if (! gDB)
  {
    // if can't open it, then create it
    err = DmCreateDatabase(0, "db1-STRT", 'STRT', 'Data', false);
    if (err) return err;
    gDB = DmOpenDatabaseByTypeCreator('Data', 'STRT', dmModeReadWrite);
    if (! gDB) return DmGetLastErr();
    // add the three strings
    AddThreeStrings();
  }
  return errNone;
}

static void AppStop(void)
{
  FrmCloseAllForms ();
  DmCloseDatabase(gDB);
}


This should be enough info to get you going...


-- 
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