Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
AddItem, AddListItem, RemoveItem, RemoveListItem anomoly
Message
From
16/02/1997 09:41:04
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
AddItem, AddListItem, RemoveItem, RemoveListItem anomoly
Miscellaneous
Thread ID:
00020718
Message ID:
00020718
Views:
95
I recently experienced a lot of grief with these commands, mainly due to the very poor documentation of these commands. Hopefully, this will save you some of that trouble.
First was the fact that AddItem operated differently than AddListItem, even though the documentation for the two is nearly identical! The major difference:
- You can add items to different cols using AddItem BUT each execution of the command will result in a full row being added, each of the OTHER columns being set up with blanks! AddListItems, however, seems to work as you would expect, in that you can invoke it several times (once to fill each col. of a row) and end up with a single row properly filled!
Here's the clincher which really got me.
This behaviour forced me to use AddListItem. This, of course, sets a "nItemID" value (which itself is extremely POORLY documented). When I wanted to delete a row I felt I should use RemoveListItem (made sense to me, having used AddListItem to add the item) but whenever I executed it I got a subscripting error! In desperation I tried RemoveItem, and got NO ERROR MESSAGE.
HOWEVER, testing the application by adding/deleting a sequence of entries randomly I quickly learned that THERE WAS INDEED A PROBLEM - by the third deletion, the next "add" was actually replacing an existing item in the list! Nothing I could do would stop this. I tried resetting all "nItemID"s after every add or delete, but still the same behaviour.
Again in desperation I searched the documentation and happened to notice that List offered a nRow & nCol parameter, so I tried populating the list with that property. IT WORKED!! (no thanks at all to ANY of the VFP documentation, which consistently states to use AddItem or AddListItem to add entries to lists).

Now RemoveItem nor RemoveItem are neither particularly well documented in the VFP docs., but a Knowledgebase article seems to supply the answer:
- The array storing the nItemIDs is NOT maintained as items are deleted [ the array remains untouched]. It further SEEMS that AddListItem looks for an equal nItemID in that array and if it finds such it decides to REPLACE the prior item with the newly furnished one. Bear in mind, though, that the entry it found in my case was for a deleted entry [in the array].

This may be operating as designed, but it is clear after this example that the operation is WRONG and leads to erroneous results.

Summary:
Stay away from AddListItem (or AddItem for that matter) and stick with List to populate lists. That way you will avoid any problems as were encountered here.

regards
Jim N.
Reply
Map
View

Click here to load this message in the networking platform