|
|
User login
Feeds |
Symbian arrays
|
|||||
| Tue, 2003-12-02 15:03 | |
Forum posts: 70
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)
MeenuJ
Forum posts: 20
I tried the way you told, and I got "expression syntax error".
Forum posts: 70
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
Forum posts: 20
The other -> did the trick. Thanks. I have no idea, how I missed it.
Forum posts: 26
/********************************************/
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??
Thx in advance
Cortii
Forum posts: 21
The other -> did the trick. Thanks. I have no idea, how I missed it.
You can also do:
(*myStuff)[0]->foo=1;
Forum posts: 21
/********************************************/
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??
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.
Forum posts: 26
Can you write me down how to append an object?
Cortii
Forum posts: 696
Can you write me down how to append an object?
// initialize element's values
element.iInteger = 10;
element.iDescriptor = KConstTextValue;
//...
iMyElementArray->AppendL(element);
Forum posts: 26
Can you write me down how to append an object?
// 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;
I declared the class like this:
{
public :
TMyMenuElement();
public :
TInt iId;
TDesC iName;
TBool iActive;
TBool iSelected;
TBool iParent;
TBool iSeparated;
};
What is the wrong with this?
Cortii
Forum posts: 364
Forum posts: 24
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
Forum posts: 26
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
Forum posts: 24
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
Forum posts: 732