×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    14

    RPointerArray Insertion and Access

    Hi,

    I am a relative newcomer to Symbian programming and am having trouble accessing (and I think updating) elements of an RPointerArray.

    This is how I am currently doing it:

    //---------------------- Inserting an element
    RPointerArray<HBufC>* iList = new(ELeave)RPointerArray<HBufC>(2);

    TBuf8<256> iBuffer = aBuffer; //This has the data to be inserted

    HBufC* tempVariable = HBufC::NewL(iBuffer.Length());
    TPtr tempPtr(tempVariable->Des());
    tempPtr.Copy(temp);
    iList->Append(tempVariable); // at index 0
    delete tempVariable;

    I think this is being done properly. However, when i access it, I am getting a NULL object.


    //--------------------- Accessing element

    HBufC* tempVariable1 = HBufC::NewL(20);
    tempVariable1 = (*iList)[0]
    gc.DrawText(*tempVariable1, rect, baseline, CGraphicsContext::ECenter, 0);

    The last line throws a KERN-EXEC panic because it is dereferencing a NULL, which means tempVariable is null.

    How do I access an element from RPointerArray properly?
    Thanks a lot!!!!!
    Vex!

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,165
    Nope KErn-Exec 3 doesn't necessarily mean NULL pointer. It means memory vilation error, and in this case it is cased by invalid pointer (that has other value than NULL).

    Just remove the following delete line

    iList->Append(tempVariable); // at index 0
    delete tempVariable;

    simply remember that the array is holding the pointer to a object and the object is somewhere elde. The tempVariable is also a pointer having same value as the zero index pointer in iList. So if you delete the tempVariable, you delete the object and leave both of the pointers to point into that area still. So then when you try using one of these pointers, it is pointing to address that used to have the object. But since it was deleted, the pointer is really not pointing to anything.

    yucca

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    14
    Thanks a lot Yucca!!
    You are the best!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×