Well, I'm going to make guesses here because you didn't include the
definition of the Database struct, but there are plenty of issues I can see.

>    Database *DB; //declaring an instance of my struct for use
>    DB = MemPtrNew(sizeof(char*) * sizeof(Database));

Let's start here... What exactly are you trying to accomplish here?
Presumably, you want a new instance of DB, but what you've actually said is
you want DB pointing to a memory block that is the size of the structure
times the size of a char * ... The size of a char * is 2 bytes in PalmOS,
and the size of your Database is ... well whatever ... so what you've done
here is allocated space twice the size of your DB structure...is this what
you meant to do?

> MemSet(&DB->dbInfo, sizeof(DB->dbInfo), 0);

Ok ... dbInfo is a member of DB, but what type is it? Are you sure you don't
mean:
MemSet (&DB->dbInfo, sizeof(<whatever type dbInfo is>), 0);

> StrCopy(DB->dbInfo.dbName, "SIR");

So, how is dbName declared in your dbInfo structure? Is it a char *dbName or
is it char dbName[<some #>]? If it's the former, then you're overwriting
memory that's not yours here because you never allocated memory for the
string.

> DB->dbInfo.passwords = DB->passwords;

Since you just created DB, DB->passwords is just some random value since you
didn't set it previously. Is this really what you mean to do?

There are other similar problems all the way through, but I think you get
the idea.

Good luck.


"Brett ---------" <[EMAIL PROTECTED]> wrote in message
news:85429@palm-dev-forum...
>
> I guess I didn't frame my question properly.  MemSet is setting my stuct
to
> a null value, so that I cannot enter data into the struct.  Here is a code
> snippit.
>
> DB is a struct containing other structs from the ThinkDB .h file.  I've
> commented where the program crashes below.  All function calls are to
> ThinkDB.c file.  This program is for my junior project in college....I'm
> getting pretty desperate on solving this problem.
>
>    Database *DB; //declaring an instance of my struct for use
>    DB = MemPtrNew(sizeof(char*) * sizeof(Database));
>
> /* First create empty database */
> MemSet(&DB->dbInfo, sizeof(DB->dbInfo), 0);
> StrCopy(DB->dbInfo.dbName, "SIR");
> DB->dbInfo.passwords = DB->passwords;
>
> TdbCreateDB(&DB->dbInfo);
>
> TdbGetDBInfo(&DB->dbInfo);
>
> /* Set Field 1 to a text field */
> MemSet(&DB->fieldPropInfo, sizeof(TdbFieldPropType), 0);
> StrCopy(DB->fieldPropInfo.dbName, "SIR");
> DB->fieldPropInfo.fieldNum = 1;
> DB->fieldPropInfo.passwords = DB->passwords;
> DB->fieldPropInfo.fieldProp.name = "Station";
> DB->fieldPropInfo.fieldProp.type = tdbFtText;
> DB->fieldPropInfo.fieldProp.props.text.defaultStr = "empty"; file://text
to
> insert into the field
> TdbSetFieldProperties(&DB->fieldPropInfo);
>
> /* Set Field 2 to a text field */
> MemSet(&DB->fieldPropInfo, sizeof(TdbFieldPropType), 0);
> StrCopy(DB->fieldPropInfo.dbName, "SIR");
> DB->fieldPropInfo.fieldNum = 2;
>
> DB->fieldPropInfo.passwords = DB->passwords;
> DB->fieldPropInfo.fieldProp.name = "Date";
> DB->fieldPropInfo.fieldProp.type = tdbFtText;
> DB->fieldPropInfo.fieldProp.props.text.defaultStr = "empty";
> TdbSetFieldProperties(&DB->fieldPropInfo);
>
> /* Set Field 3 to a text field */
> MemSet(&DB->fieldPropInfo, sizeof(TdbFieldPropType), 0);
> StrCopy(DB->fieldPropInfo.dbName, "SIR");
> DB->fieldPropInfo.fieldNum = 3;
>
> DB->fieldPropInfo.passwords = DB->passwords;
> DB->fieldPropInfo.fieldProp.name = "O2";
> DB->fieldPropInfo.fieldProp.type = tdbFtText;
> DB->fieldPropInfo.fieldProp.props.text.defaultStr = "empty";
> TdbSetFieldProperties(&DB->fieldPropInfo);
>
> /* Set Field 4 to a text field */
> MemSet(&DB->fieldPropInfo, sizeof(TdbFieldPropType), 0);
> StrCopy(DB->fieldPropInfo.dbName, "SIR");
> DB->fieldPropInfo.fieldNum = 4;
>
> DB->fieldPropInfo.passwords = DB->passwords;
> DB->fieldPropInfo.fieldProp.name = "Salinity";
> DB->fieldPropInfo.fieldProp.type = tdbFtText;
> DB->fieldPropInfo.fieldProp.props.text.defaultStr = "empty";
> //crahses at the statement below.  My struct has a value of NULL and
cannot
> enter data here.
> TdbSetFieldProperties(&DB->fieldPropInfo);
>
> /* Set Field 5 to a text field */
> MemSet(&DB->fieldPropInfo, sizeof(TdbFieldPropType), 0);
> StrCopy(DB->fieldPropInfo.dbName, "SIR");
> DB->fieldPropInfo.fieldNum = 5;
>
> DB->fieldPropInfo.passwords = DB->passwords;
> DB->fieldPropInfo.fieldProp.name = "Comments";
> DB->fieldPropInfo.fieldProp.type = tdbFtText;
> DB->fieldPropInfo.fieldProp.props.text.defaultStr = "empty";
> TdbSetFieldProperties(&DB->fieldPropInfo);
>
> /* Add the record */
> StrCopy(DB->recordInfo.dbName, "SIR");
> DB->recordInfo.passwords = DB->passwords;
> DB->recordInfo.fieldValues = 0L;
> TdbAddRecord(&DB->recordInfo);




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

Reply via email to