Deleting all CShape in CShapes

discostu
05-16-2005, 01:25 PM
Hi, I have a member variable CShapes m_carPath for which I do AddLine( oldlocation, newlocation ) each time I update the car's position (represented by a pushpin). I have a reset button in this MFC app that when pressed deletes the pushpin representing the car and also attempts to delete all the lines associated with m_carPath (these are of type CShape). My code below seems to only delete every other line:
VARIANT idx;
VariantInit( &idx );
V_VT(&idx) = VT_I4;
for( long i = 1; i <= m_carPath.GetCount(); i++ ) {
V_I4(&idx) = i;
CShape shape = m_carPath.GetItem( &idx );
shape.Delete();
}
If I hit "Reset" over and over, more and more lines go away.
Any idea why? Please help. Thanks! -Stu

Wilfried
05-16-2005, 01:55 PM
Hi,

I dont understeand the question very whell but is it not more easy to just move the pushpin to the new position and eventually change balloon information ?

discostu
05-16-2005, 02:48 PM
Ok, my question was not about the pushpin. It was about a line that I am drawing to trail the pushpin. But your answer posts another question for me. So, I'm going to try and make it clear with two questions.


How do you just move a pushpin in c++? I read on the forums that you have to delete it everytime and make a new one at the new location.
My original question: Why does my code not delete all CShape instances in CShapes. In my OnTimer() function I "move" the pushpin (by deleting it, and making a new one -- see question 1). In the same OnTimer() function I also do AddLine(oldLocation, newLocation) to my CShapes instance. When I try to delete all these lines in CShapes instance. Only some, get deleted (it looks to be every other one).


If this is not clear let me know.
Thanks!
Stu

Wilfried
05-17-2005, 12:46 PM
Hi,

Now I understeand :)

This example try to find a pushpin on the map, create a new if not found, and move the existing with the same name if found:

private Pushpin MovePP(string name, double lat, double lon)
{
Location Loc = MP.ActiveMap.GetLocation(lat, lon, 1);
Pushpin PP = MP.ActiveMap.FindPushpin(name);
if (PP == null)
PP = MP.ActiveMap.AddPushpin(Loc, name);
PP.Location = Loc;
PP.GoTo();
return PP;
}


As for your code, it will delet every other one because you delete very other one because of the index (i).. If you change it with a while loop it will work. Now you delete, then the index is removed, count is decrement, you increment index and delete 1 step higher. Common mistakes we all do once a while :)

 
Web mp2kmag.com
mapforums.com