Maria,
First, I have a couple questions.

1)  Why are you using dmMaxRecordIndex as your index in DmQueryRecord(dbPtr,
index)?  If you know there is only one record, the index will not be
dmMaxRecordIndex.  From my experience, the index should be zero.  If you
have used DmNewRecord to create a single new record using dmMaxRecordIndex,
then the index will be zero if there were no other records.
2)  If you know the strings are NULL terminated and you know the maximum
length will not exceed the buffer you will copy to, why use StrNCopy?
3)  If the strings are a specific size (as stated with maxIdLength &
maxNameLength) then why use StrLen(i)?  Don't you already know the length?
4)  from the following, id[maxIdLength-1] = 0, is your needed id length = 3
and name length = 19?  If you are actually needing 4 and 20, then you are
cutting one character off the end. (i.e. maxIdLength = 4, id="1234", id[4-1]
= 0, so id[3] = 0, id now="123")
5)  Have you debugged through the code to find the exact line the error is
appearing?

It might be helpful if we knew how the record was created.  To me, it looks
like you are trying to use NULL as a separator in a char* so you can store
less than your expected sizes of 4 and 20.  If this is the case, I believe
the error may be your StrNCopy functions tying to copy past the end of your
string.  If you are not using NULL as a separator, and you are forcing the
length to 4 and 20, then there is no reason to have a NULL.  You can then
use StrNCopy as expected.

I hope some of this helps...You can do some searching in the archives too.
There should be some references to compacting database records using NULL
separators instead of static sizes.

--
Jeremy Griffith,
Web Master/Web Applications Developer (http://www.gradebook.com)
Excelsior Software, Inc.  (970) 353-8311
[EMAIL PROTECTED]


"maria j�nsson" <[EMAIL PROTECTED]> wrote in message
news:63744@palm-dev-forum...
>
> Hi all!
>
> I try to get some data from a database and put it in two variabels(id and
> name).
> But when I call the load state I get the following message:
>
> CTR just read from memory location 0x00000006,
> which is low memory.
>
> "Low memory" is defined as the first 256 bytes of memory. It should not be
> directly accessed by applications under any circumstances.
>
> I know that there is one record in the database, but I just can't get it!
>
> Would be very grateful if some of you could lock thrugh the following
> code-snippet and tell me if I got something wrong! Thanks in advance
//Maria
>
> Err ResourceHH::loadState()
> {
> UInt16 maxIdLength=4;
> UInt16 maxNameLength=20;
>
> dbPtr = DmOpenDatabaseByTypeCreator('F','ZMgd',dmModeReadWrite);
> UInt16 index = dmMaxRecordIndex;
>
> // Open the record for reading:
> MemHandle h = DmQueryRecord(dbPtr, index);
> // Make sure we got a good memory handle:
> if(!h)
> return 1;
> else
> {
> // Lock the handle, so we can read from it:
> Char *i = (Char *) MemHandleLock(h);
> // Get the length of the id - we can use StrLen since the name
> // is stored like a regular null-terminated string:
> UInt16 iLen = StrLen(i);
> // The name is stored immediately after the id:
> Char *n = i+iLen+1;
>
> // Now copy the two strings, and make sure they are null-terminated:
> StrNCopy(id, i, maxIdLength);
> id[maxIdLength-1] = 0;
> StrNCopy(name, n, maxNameLength);
> name[maxNameLength-1] = 0;
>
> // Remember to unlock the handle now that we're done with it:
> MemHandleUnlock(h);
> }
>
> // Everything went smoothly:
> return 0;
>
>
> }
>
> _________________________________________________________________
> H�mta MSN Explorer kostnadsfritt p� http://explorer.msn.se
>
>
>



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