Error in ListBox->GetDataItemPtr
Klaus Kurzawa -- klausk@saruman.cadpoint.se
Friday, January 05, 1996
Text item: Text_1
Hi,
Can someone tell me why this procedure always fails. Could the error
be somewhere else?
// Getting the listbox
//
CListBox* pLB=(CListBox*)GetDlgItem(IDC_LBOX_OBJECTS);
// This is a valid array
//
CTypedPtrArray&Object = GetObjectTable();
for (int cI=0; cIAddString("Test string"); // Add a string
pLB->SetItemDataPtr(cI, (void*)Object[cI]); // Save the at the row
// This prints the correct addresses for each index
//
TRACE("\ncI:%d pPtr:%ld", cI, pLB->GetItemDataPtr(cI));
}
// This prints all zero
TRACE("\ncI:%d pPtr:%ld", 0, pLB->GetItemDataPtr(0));
RESULT:
cI:1 pPtr:4484520
cI:2 pPtr:4485044
cI:3 pPtr:4485732
cI:0 pPtr:0 <- Error!!
Please help me! This error just began and I don't know when it
started.
/Klaus Kurzawa
klausk@cadpoint.se
Joern Dahl-Stamnes -- Jorn.Dahl-Stamnes@fysel.unit.no
Monday, January 08, 1996
>Text item: Text_1
>
> Hi,
>
> Can someone tell me why this procedure always fails. Could the error
> be somewhere else?
>
> // Getting the listbox
> //
> CListBox* pLB=(CListBox*)GetDlgItem(IDC_LBOX_OBJECTS);
>
> // This is a valid array
> //
> CTypedPtrArray&Object = GetObjectTable();
> for (int cI=0; cI {
> pLB->AddString("Test string"); // Add a string
> pLB->SetItemDataPtr(cI, (void*)Object[cI]); // Save the at the row
Try this:
int index = pLB->AddString("Test string"); // Add a string
pLB->SetItemDataPtr(index, (void*)Object[cI]); // Save the at the row
Hope this help.
>
> // This prints the correct addresses for each index
> //
> TRACE("\ncI:%d pPtr:%ld", cI, pLB->GetItemDataPtr(cI));
> }
>
> // This prints all zero
> TRACE("\ncI:%d pPtr:%ld", 0, pLB->GetItemDataPtr(0));
>
> RESULT:
> cI:1 pPtr:4484520
> cI:2 pPtr:4485044
> cI:3 pPtr:4485732
> cI:0 pPtr:0 <- Error!!
>
> Please help me! This error just began and I don't know when it
> started.
>
> /Klaus Kurzawa
> klausk@cadpoint.se
--
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Joern Yngve Dahl-Stamnes, The University of Trondheim, Norway |
| e-mail: Jorn.Dahl-Stamnes@fysel.unit.no |
| phone : +73 59 44 12, fax: +73 59 14 41 |
| Surfing the net? Try http://www.fysel.unit.no/dahls/dahls.html |
| NetCrack not required! |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Dale Wilson -- dale@dra.com
Tuesday, January 09, 1996
> > for (int cI=0; cI > {
> > pLB->AddString("Test string"); // Add a string
> > pLB->SetItemDataPtr(cI, (void*)Object[cI]); // Save the at the
row
> > /Klaus Kurzawa
> > klausk@cadpoint.se
>
> Try this:
> int index = pLB->AddString("Test string"); // Add a
> string
> pLB->SetItemDataPtr(index, (void*)Object[cI]); // Save the at the
row
> | Joern Yngve Dahl-Stamnes, The University of Trondheim, Norway |
Joern didn't explain why his fix works, but once I saw it, it was *obvious*.
You probably have the list box sorting your items for you, so the index of
the item you just added is not cl, but rather the position at which the item
landed in the sorted order.
Dale Wilson dale@dra.com
| Вернуться в корень Архива
|