struct Database Storage

Discuss OrbForms Designer and PocketC Architect

Postby Ringmaster on Sun May 05, 2002 3:37 pm

How the heck do you store structs in a pdb?

I have allocated space for multiples of this struct:
<pre id=code><font face=courier size=2 id=code>
struct Stat {
int stype;
string name;
string value;
string specialty;
};
</font id=code></pre id=code>


Like so:
<pre id=code><font face=courier size=2 id=code>
stats = new Stat[statcount];
</font id=code></pre id=code>


<i>stats</i> is inside an object (don't know if this makes a difference, but I'll mention it):
<pre id=code><font face=courier size=2 id=code>
object WWChar {
Stat* stats;
int statcount;
};
</font id=code></pre id=code>


Now I want to store all of <i>stats</i> in a pdb. I figure I have two ways of doing this:
<ol type=1>
<li>Write each Stat from stats in a separate record.</li>
<li>Write the statcount into one record, and the whole of stats into another.</li>
</ol id=1>


Opting for the second approach, I tried this:
<pre id=code><font face=courier size=2 id=code>
//database init stuff, then...
z = 0;
db.newrec(&z, rec);
rec.write(&wwchar.statcount, typeof(wwchar.statcount), 1);
rec.close();
z++;
db.newrec(&z, rec);
rec.write(&wwchar.stats[0], typeof(wwchar.stats[0]), wwchar.statcount);
rec.close();
</font id=code></pre id=code>


Then I tried this to retrieve it:
<pre id=code><font face=courier size=2 id=code>
db.getrec(0, rec, true);
rec.read(&wwchar.statcount, typeof(wwchar.statcount), 1);
rec.close();
wwchar.AllocStats(wwchar.statcount); //Allocates space, as written above
db.getrec(1, rec, true);
rec.read(&wwchar.stats, typeof(wwchar.stats[0]), wwchar.statcount);
rec.close();
</font id=code></pre id=code>


But I get a "Type mismatch" error when it tries to read a saved database.

So... Am I writing it wrong or readig it wrong? What's the problem here?
Ringmaster
 
Posts: 11
Joined: Tue Mar 19, 2002 2:49 am

Postby dewey on Sun May 05, 2002 10:19 pm

When you read the stats back in, you call read with &wwchar.stats, which is the address of the pointer. You either want to use wwchar.stats or &wwchar.stats[0]
dewey
Site Admin
 
Posts: 749
Joined: Sun Oct 21, 2007 5:12 am


Return to OrbForms Designer and PocketC Architect

Who is online

Users browsing this forum: No registered users and 2 guests

cron