I'm having problems with my database usage.  At the moment, I'm just trying 
to save a name entered by the user in a text field and display that saved 
name in a different form.  I know databases aren't necessary for trivial 
things like this, but I'm starting out easy to get my head around databases. 
Can anyone help me out?

First, I've got a struct like this:

typedef struct {
    char TrackName[20];
} DBRecord;


Here's my saving code:

FieldPtr        fld;
FormPtr         frm;
Int             itemIndex;
CharPtr         newTrackName;
VoidHand        h;
UInt16 index = 0;
DBRecordType    r;

frm = FrmGetActiveForm();
itemIndex = FrmGetObjectIndex(frm, TrackRecordNameField);
fld = FrmGetObjectPtr(frm, itemIndex);
newTrackName = FldGetTextPtr(fld);
h = DmNewRecord(DB, &index, sizeof(r));
StrCopy(r.TrackName, newTrackName);
if (h) {
    VoidPtr p = MemHandleLock(h);
    Err err = DmWrite(p, 0, &r, sizeof(r));
    MemPtrUnlock(p);
    DmReleaseRecord(VictoryDB, index, true);
}


And here's my loading code:

FieldPtr        fld;
FormPtr         frm;
Int             itemIndex;
CharPtr         newTrackName = 0;
VoidHand        h;
UInt            index = 0;

frm = FrmGetActiveForm();
itemIndex = FrmGetObjectIndex(frm, ShowTrackNameField);
fld = FrmGetObjectPtr(frm, itemIndex);
// get the handle to the record
h = DmQueryRecord(VictoryDB, index);
if (h) {
    DBRecordType * p = (DBRecordType *) MemHandleLock(h);
    StrCopy(newTrackName, p->TrackName);
    MemPtrUnlock(p);
}
FldSetTextPtr(fld, newTrackName);
FldDrawField(fld);


Thanks,
Sean

_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.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