Symbian arrays

Login to reply to this topic.
Tue, 2003-12-02 15:03
Joined: 2003-11-04
Forum posts: 20
I have defined things like:

Code:
struct Stuff
{
int foo;
};

CArrayPtrFlat<Stuff> * myStuff;

How do I get to modify objects in the array?

Code:
myStuff[0].foo = 1;

Gives me an error.  Huh

Tue, 2003-12-02 16:06
Joined: 2003-07-22
Forum posts: 70
Symbian arrays
Hi
U have to use it in the following way.

myStuff->At(0).foo = 1;

(In the given code you have not created the array. I hope u have created the array. Like  myStuff = new (ELeave) CArrayPtrFlat<Stuff > (1)Wink

MeenuJ
Tue, 2003-12-02 16:27
Joined: 2003-11-04
Forum posts: 20
Symbian arrays
Yea, of course I create it.  Smiley But what I have here is a compiler error.

I tried the way you told, and I got "expression syntax error".  Cry
Tue, 2003-12-02 17:02
Joined: 2003-07-22
Forum posts: 70
Symbian arrays
Hi
I have just tried it and it is working

CArrayPtrFlat<Stuff> *myStuff = new (ELeave) CArrayPtrFlat<Stuff> (1);

   Stuff abc;
   Stuff abc1;

   myStuff->AppendL(&abc);
   myStuff->AppendL(&abc1);

   myStuff->At(0)->foo =1;


MeenuJ
Tue, 2003-12-02 17:10
Joined: 2003-11-04
Forum posts: 20
Symbian arrays
myStuff->At(0)->foo =1;

The other -> did the trick. Thanks. I have no idea, how I missed it.  Embarassed
Sun, 2004-10-10 22:47
Joined: 2004-09-14
Forum posts: 26
Symbian arrays
I've defined the following struct:

/********************************************/

   struct MenuElement
   {
      TInt   iId;
      TDesC   iName;
      TBool   iActive;
      TBool   iSelected;
      TBool   iParent;
      TBool   iSeparated;
   };

   CArrayPtrFlat<MenuElement> *iElement = new (ELeave) CArrayPtrFlat<MenuElement> (1);

/*********************************************/

The debugger say no errors, so I think the sruct is created, but if
i try to add element to the struct the debugger also say no error, but the emulator rise E32USER-CBASE 21 I've read the panic's text, and it say that the array hasn't got any element if this panic occur.


I've tryed to add element like this:

/*********************************************/

   iElement->At(0)->iId = 1;
   iElement->At(0)->iName = _L("Open");
   iElement->At(0)->iActive = ETrue;
   iElement->At(0)->iSelected = ETrue;
   iElement->At(0)->iParent = EFalse;
   iElement->At(0)->iSeparated = ETrue;

/*********************************************/


So, my question is how can I add elements the correct way?? Smiley


Thx in advance

Cortii

Tue, 2004-10-12 02:38
Joined: 2004-10-12
Forum posts: 21
Symbian arrays
Quote from: asbaa
myStuff->At(0)->foo =1;

The other -> did the trick. Thanks. I have no idea, how I missed it.  Embarassed

You can also do:

(*myStuff)[0]->foo=1;
Tue, 2004-10-12 02:39
Joined: 2004-10-12
Forum posts: 21
Symbian arrays
Quote from: Cortii
I've defined the following struct:

/********************************************/

   struct MenuElement
   {
      TInt   iId;
      TDesC   iName;
      TBool   iActive;
      TBool   iSelected;
      TBool   iParent;
      TBool   iSeparated;
   };

   CArrayPtrFlat<MenuElement> *iElement = new (ELeave) CArrayPtrFlat<MenuElement> (1);

/*********************************************/

The debugger say no errors, so I think the sruct is created, but if
i try to add element to the struct the debugger also say no error, but the emulator rise E32USER-CBASE 21 I've read the panic's text, and it say that the array hasn't got any element if this panic occur.


I've tryed to add element like this:

/*********************************************/

   iElement->At(0)->iId = 1;
   iElement->At(0)->iName = _L("Open");
   iElement->At(0)->iActive = ETrue;
   iElement->At(0)->iSelected = ETrue;
   iElement->At(0)->iParent = EFalse;
   iElement->At(0)->iSeparated = ETrue;

/*********************************************/


So, my question is how can I add elements the correct way?? Smiley


Thx in advance

The problem is you have not added an object to the array before you start trying to set properties in that element.

You need to InsertL() or AppendL() an element first.
Thu, 2004-10-14 08:48
Joined: 2004-09-14
Forum posts: 26
Symbian arrays
Yes, I know this, but I don't know how to use AppendL() when the array has more fields than one...  Sad

Can you write me down how to append an object? Smiley

Cortii

Thu, 2004-10-14 09:14
Joined: 2003-12-05
Forum posts: 696
Symbian arrays
Quote from: Cortii
Yes, I know this, but I don't know how to use AppendL() when the array has more fields than one...  Sad

Can you write me down how to append an object? Smiley

Code:
TMyMenuElement element;

// initialize element's values
element.iInteger = 10;
element.iDescriptor = KConstTextValue;
//...

iMyElementArray->AppendL(element);
Sun, 2004-10-17 18:23
Joined: 2004-09-14
Forum posts: 26
Symbian arrays
Quote from: Andreas
Quote from: Cortii
Yes, I know this, but I don't know how to use AppendL() when the array has more fields than one...  Sad

Can you write me down how to append an object? Smiley

Code:
TMyMenuElement element;

// initialize element's values
element.iInteger = 10;
element.iDescriptor = KConstTextValue;
//...

iMyElementArray->AppendL(element);


Ok, now this is clear, but the TMyMenuElement is a class isn't it? I wrote this class declaration into the header file, but the compiler writting this, when I try to use TMyMenuElement element;

Code:
LNK2001: unresolved external symbol "public ___thiscall TMyMenuElement::TMyMenuElement(void)"

I declared the class like this:

Code:
class TMyMenuElement
{
public :
TMyMenuElement();
public :
TInt iId;
TDesC iName;
TBool iActive;
TBool iSelected;
TBool iParent;
TBool iSeparated;
};

What is the wrong with this? Sad

Cortii

Sun, 2004-10-17 19:42
Joined: 2004-07-10
Forum posts: 364
Symbian arrays
Is it in the same DLL? If not you'll have to EXPORT_C it
Sun, 2004-10-17 21:00
Joined: 2003-09-01
Forum posts: 24
Symbian arrays
I believe your problem is different. The linker is complaining about a missing default constructor because no such constructor can be created. This is due to the fact that you have a TDesC member in your struct.

You cannot have a TDesC variable in your code, only as a reference, or as a pointer. This is because TDesC is a base class and cannot be instantiated. Instead, your struct should have either a TBuf<>, or an HBufC *, or something like that.
And I really recommend that you read thoroughly chapter 5 (Strings and Descriptors) in the book Symbian OS C++ for Mobile Phones before you go any further

ariel

Sun, 2004-10-17 22:48
Joined: 2004-09-14
Forum posts: 26
Symbian arrays
Quote from: ariel
I believe your problem is different. The linker is complaining about a missing default constructor because no such constructor can be created. This is due to the fact that you have a TDesC member in your struct.

You cannot have a TDesC variable in your code, only as a reference, or as a pointer. This is because TDesC is a base class and cannot be instantiated. Instead, your struct should have either a TBuf<>, or an HBufC *, or something like that.
And I really recommend that you read thoroughly chapter 5 (Strings and Descriptors) in the book Symbian OS C++ for Mobile Phones before you go any further


Now I've left the TDesC variable from the structure... and I'm getting the same error like before...

Cortii

Mon, 2004-10-18 12:24
Joined: 2003-09-01
Forum posts: 24
Symbian arrays
The same linker error?
That's weird. I think it's time for some voodoo now: clean all intermediate files, rebuild all, make sure the .cpp with the struct is in the mmp file, etc.
If all that fails, post here some code so we can have a better idea. It also might be useful to know what is your target platform

ariel

Mon, 2005-06-27 08:27
Forum Nokia Champion
Joined: 2004-05-26
Forum posts: 732
Re: Symbian arrays
Have you got any solution for the above panic? Can you please post if you solved the issue?

  • Login to reply to this topic.