×

Discussion Board

Results 1 to 3 of 3
  1. #1
    chishti.hameed
    Guest

    plz check this code

    My app get close when i try to append item in list :-(

    listBoxItems->AppendL(array->MdcaPoint(i));

    commiting this line loads only what i've in .rss but app dont crash.

    ////////////////////////////////////////////////////////////////////
    void CListContainer::ConstructL(const TRect& aRect)
    {
    CreateWindowL();

    CreateListL();
    ReadDataFromFile();
    iLogListBox->SetListBoxObserver(this);
    SetupListIconsL();
    SetupScrollBarsL();
    SetRect(aRect);
    ActivateL();
    }

    void CListContainer::CreateListL()
    {

    iLogListBox = new (ELeave) CAknSingleGraphicStyleListBox;
    iLogListBox->SetContainerWindowL(*this);

    TResourceReader reader;
    iEikonEnv->CreateResourceReaderLC(reader, R_LOG_LISTBOX);
    iLogListBox->ConstructFromResourceL(reader);

    CleanupStack::PopAndDestroy(); // reader

    }

    void CListContainer::SetupScrollBarsL()
    {
    iLogListBox->CreateScrollBarFrameL(ETrue);
    iLogListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
    CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
    }


    void CListContainer::SetupListIconsL()
    {

    // Get the name of the file containing the icons
    HBufC* iconFileName;
    iconFileName = StringLoader::LoadLC(R_ICON_FILE_NAME); // Pushes iconFileName onto the Cleanup Stack.

    // Create an array of icons, reading them from the file
    CArrayPtr<CGulIcon>* icons = new(ELeave) CAknIconArray(ArrayLength);
    CleanupStack::PushL(icons);

    //add icons
    if (ArrayLength != 0)
    {
    for (TInt i=0; i<ArrayLength; i++ )
    {
    icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, EMbmSmsorLog, EMbmSmsorLog_mask));
    }
    }


    CleanupStack::Pop(icons);
    CleanupStack::PopAndDestroy(iconFileName);

    iLogListBox->ItemDrawer()->ColumnData()->SetIconArray(icons); // passing ownership of icons

    }

    void CListContainer::ReadDataFromFile()
    {

    RFs& fs = CCoeEnv::Static()->FsSession(); // 'global' file server session
    CDesCArray* array = new(ELeave) CDesCArrayFlat(1); // use this array type rather
    CleanupStack::PushL(array);

    RFile file;
    User::LeaveIfError(file.Open(fs, KFileName, EFileRead | EFileStreamText));
    CleanupClosePushL(file);

    TBuf8<40> buf8;
    TBuf<40> buf16;
    for (;
    {
    User::LeaveIfError(file.Read(buf8));
    const TDesC8& aText = buf8;
    buf16.Copy(aText); //copy buf8 - > buf16
    const TDesC& aText16 = buf16;

    TLex aLex(aText16);
    aLex.Mark();
    while(aLex.Peek() != '\n') aLex.Inc();
    TPtrC aStr = aLex.MarkedToken();
    aLex.Inc();
    array->AppendL(aStr);

    //check if we've reached end of file
    if (buf8.Length() != 40)
    break;
    }

    // get array length
    ArrayLength = 0;
    ArrayLength = array->Length();

    //Add to list box
    CTextListBoxModel* model = iLogListBox->Model();
    MDesCArray* textArray = model->ItemTextArray();
    CDesCArray* listBoxItems = static_cast<CDesCArray*>(textArray);

    //insert items to listbox
    if (ArrayLength != 0)
    {
    for (TInt i=0; i<ArrayLength; i++ )
    {
    //when i comment this line it dont get crash and loads 2 items
    //which i've in .rss file
    listBoxItems->AppendL(array->MdcaPoint(i));
    }
    }

    /* //
    iLogListBox->Model()->SetItemTextArray(array);
    iLogListBox->Model()->SetOwnershipType(ELbmOwnsItemArray);
    */
    iLogListBox->HandleItemAdditionL(); // This also redraws the list box.
    iLogListBox->SetCurrentItemIndex(0);
    iLogListBox->SetFocus(ETrue);

    // close file and clean up
    CleanupStack::PopAndDestroy(2,array); // array & file
    }

    ///////////////////////////////////////////////////////
    .Rss


    RESOURCE LISTBOX r_listbox
    {
    array_id = r_items;
    flags = EAknListBoxSelectionList;
    }

    RESOURCE ARRAY r_items
    {
    items =
    {
    LBUF
    {
    txt = ITEM_ONE;
    },
    LBUF
    {
    txt = ITEM_TWO;
    }
    };
    }

  2. #2
    Regular Contributor
    Join Date
    Feb 2005
    Posts
    328
    Are you getting a panic code? Also are you working in the emulator on on the device?

    Type of listbox is...

    iLogListBox = new (ELeave) CAknSingleGraphicStyleListBox;

    ... so you have to include a graphic index for each line in your listbox.

    eg

    for (TInt i=0; i<array->Count(); i++)
    {
    TFileName listitem(_L("0\t")); // the 0 indicates the 1st graphic in your list as set up in SetupListIconsL()
    listitem += (*array)[i]; // add the actual text you want to display
    listBoxItems->AppendL(listitem);
    }
    iLogListBox->HandleItemAdditionL();

    And a note about naming conventions:

    ReadDataFromFile()

    should read

    ReadDataFromFileL()

    ... as it is possible for this function to leave

  3. #3
    chishti.hameed
    Guest

    template60 u my GURU :-)

    many many thanks for help...
    it works fine now :-)

    I really didnt understand much what these 2 lines do????:

    TFileName listitem(_L("0\t"));
    listitem += (*array)[i];

Posting Permissions

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