Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 112

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 112

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 112

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 112

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 112

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 112
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3368: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3370: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3371: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3372: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
OrbWorks Community Forum • View topic - Weird Bub in PCA

Weird Bub in PCA

Discuss OrbForms Designer and PocketC Architect

Weird Bub in PCA

Postby gmyx on Sun Aug 10, 2008 4:58 pm

Assuming the following structures:
Code: Select all
struct Card {
int Suit;
int Value;
}

struct Deck {
int min;
int max;
Card* Cards; }


The type string of Deck is "iip". However, you can't use pointers when saving data to a database. Here comes my problem.

Indirect Method:
Code: Select all
SaveRec(Database* aDB, void* pdata, string type, int count)
{
DBRecord lDBRec;
int liIndex;

liIndex = -1;
aDB->newrec(&liIndex, lDBRec);
lDBRec.write(pdata, type, count);
lDBRec.close();
}


For my deck structure, the type var is set to "50i" (it's not a full deck). Calling the above method works like this:
Code: Select all
SaveRec(&lDB, &gDeck, "50i",1)


However, I'm in the process of changing my code and removed the SaveRec function to replace it with a direct function. In the function below, It fails with type mismatch. The database is declared elsewhere.
Code: Select all
SaveDB() {
DBRecord lDBRec;
int liIndex;

liIndex = -1;
gDB.newrec(&liIndex, lDBRec);

lDBRec.write( &gDeck, "50i", 1); // fails on this line
[...]
}


Additional notes: the "50i" is calculated in code - I just put in the value here for simplicity. The indirect method saves the entire Deck structure and is retrievable later correctly.

Which code contains the bug? Is the indirect method the only way? Or should both ways work or should both ways fail?

Thank you for your help.
gmyx
 
Posts: 8
Joined: Thu Nov 02, 2006 4:39 pm

Re: Weird Bub in PCA

Postby nmc on Mon Aug 11, 2008 6:13 pm

you missed to tell us what gDeck is ;-)

Is it

Code: Select all
Deck gDeck;


or is it

Code: Select all
Card gDeck[25];
...
MyDeck.Cards = gDeck;


With the second definition your (direct) code should work, with the first it cant, because "iip" != "50i" ==> type mismatch;
you could try "gDeck.cards" (depends on how you "fill" the pointer-member)
nmc
 
Posts: 197
Joined: Tue May 27, 2003 8:42 pm
Location: Germany

Re: Weird Bub in PCA

Postby gmyx on Mon Aug 11, 2008 7:03 pm

Opps. gDeck is defined as
Code: Select all
Deck gDeck;


Card is filled using
Code: Select all
Cards = new Card[GetDeckSize()];

Note: This is done from within the Deck structure.

I know that "iip" != "50i". The odd thing is, I didn't change the definition of Deck - I just changed how and when it's saved. It works when the data is saved during a onStop() event and does not when after initialization using the new code. That is the only code change here.

The thing is, I'm trying to convert from saving during a onStop() event as the save time is starting to get long. It was fine until I put the save code during a onTimer() event.

Thanks for your help.
gmyx
 
Posts: 8
Joined: Thu Nov 02, 2006 4:39 pm

Re: Weird Bub in PCA

Postby nmc on Tue Aug 12, 2008 8:33 am

Just think about how the things will be held in memory;
if your method has worked before, then the two memory blocks (Deck structure allocated at compile time and Card structure allocated at runtime) must have been direct neigbours - do you really want to rely on this assumption?

I would suggest an save-method like this:
Code: Select all
...
lDBRec.write(&gDeck, "ii", 1); // min/max
lDBRec.write(gDeck->Cards, "50i", 1); // 25 suit/value pairs
...
nmc
 
Posts: 197
Joined: Tue May 27, 2003 8:42 pm
Location: Germany

Re: Weird Bub in PCA

Postby gmyx on Tue Aug 12, 2008 12:05 pm

nmc wrote:Just think about how the things will be held in memory;
if your method has worked before, then the two memory blocks (Deck structure allocated at compile time and Card structure allocated at runtime) must have been direct neigbours - do you really want to rely on this assumption?

I would suggest an save-method like this:
Code: Select all
...
lDBRec.write(&gDeck, "ii", 1); // min/max
lDBRec.write(gDeck->Cards, "50i", 1); // 25 suit/value pairs
...


Oh, I understand that! I just thought it weird that it worked the first time and not the second. I guess the first situation should of failed at run time but didn't. That was what confused me - I thought the write function was being more intelligent and looking what the pointer was pointing and saving that. Oh well, it's code change time!

Thanks for you help nmc (What does that stand for? The only thing that comes to mind is No Movement Clause)
gmyx
 
Posts: 8
Joined: Thu Nov 02, 2006 4:39 pm


Return to OrbForms Designer and PocketC Architect

Who is online

Users browsing this forum: No registered users and 5 guests

cron