Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



How to construct a descriptor array

The following code fragments show construction of a CDesCArrayFlat and a CPtrCArray. Both array types can take any type of descriptor as source when adding a new array element.

Constructing and using a CDesCArraySeg is the same as the same as a CDesCArrayFlat.

First, construct a set of descriptors:

_LIT(KText1,"abcdefg");
_LIT(KText2,"hijk");
_LIT(KText3,"lmnopqr");
_LIT(KText4,"stuvwxyz");
...
TBufC<8> buffer1(KText1); // a non-modifiable buffer descriptor
TBuf<8> buffer2(Ktext2); // a modifiable buffer descriptor
...
TPtrC ptr1(Ktext3); // a non-modifiable pointer descriptor
TPtr ptr2; // a modifiable pointer descriptor
ptr2 = buffer1.Des(); // pointing to the data in buffer1
...
HBufC* heapbuff = HBufC::NewL(8); // a heap descriptor
*heapbuff = KText4;

Now add the five descriptors to a CDesCArrayFlat

CDesCArrayFlat* descarray;
...
descarray = new (ELeave) CDesCArrayFlat(5);
...
descarray->AppendL(buffer1);
descarray->AppendL(buffer2);
descarray->AppendL(ptr1);
descarray->AppendL(ptr2);
descarray->AppendL(*heapbuff);
...
TInt len = descarray->MdcaPoint(2).Length();// information about
                                            // the third element
...

and add the five descriptors to a CPtrCArray

CPtrCArray* ptrcarray;
...
ptrcarray = new (ELeave) CPtrCArray(5);
...
ptrcarray->AppendL(buffer1);
ptrcarray->AppendL(buffer2);
ptrcarray->AppendL(ptr1);
ptrcarray->AppendL(ptr2);
ptrcarray->AppendL(*heapbuff);
...
TInt len = ptrcarray->MdcaPoint(2).Length();// information about
                                            // the third element
...