software crashes when I try to delete a shape

leopoldB
11-26-2007, 10:34 AM
I am writing my code in C++ and at this point all I want to do is add a line to the map and then be able to delete it. I can add the line just fine and I do it with the following code:

void MapPt:: DrawLine(double Lat1, double Long1, double Lat2, double Long2)
{
//create a location object for each point
WyptLocPtr1 = m_myMap->GetLocation( Lat1, Long1, 4 );
locWypt1 = (Location*)WyptLocPtr1;
WyptLocPtr2 = m_myMap->GetLocation( Lat2, Long2, 4 );
locWypt2 = (Location*)WyptLocPtr2;

//create a shapes object
NavLinesPtr = m_myMap->GetShapes();
NavLines = (Shapes*)NavLinesPtr;

Shape* L;
L = NavLines->AddLine(locWypt1,locWypt2);
}

After I have created this line on the map I cannot delete it though. To delete I just use the following code:

Line->Delete()

My software just crashes here, and the error I get is access violation. Any help here would be much appreciated.

Winwaed
11-26-2007, 09:19 PM
Sounds like your pointer is no longer valid.
(I assume you meant "L" and not "Line"?)



Richard

leopoldB
11-27-2007, 07:47 AM
I figured it out. I need two pointers to get it to work. I needed to first get a ShapePtr and then cast that to a Shape*. With this my code works.

Eric Frost
11-27-2007, 08:08 AM
Can you post the new code for an example if others have the same problem?

Thanks, :lol:
Eric

leopoldB
11-27-2007, 08:27 AM
Here is my working code:

void MapPt:: DrawLine(double Lat1, double Long1, double Lat2, double Long2)
{

//first must create a location object for each point
WyptLocPtr1 = m_myMap->GetLocation( Lat1, Long1, 4 );
locWypt1 = (Location*)WyptLocPtr1;
WyptLocPtr2 = m_myMap->GetLocation( Lat2, Long2, 4 );
locWypt2 = (Location*)WyptLocPtr2;

//create a shape object
NavLinesPtr = m_myMap->GetShapes();
NavLines = (Shapes*)NavLinesPtr;

//draw line
LinePtr = NavLines->AddLine(locWypt1,locWypt2);
Line = (Shape*)LinePtr;
}

To delete the line all I do is call:

LinePtr->Delete();

 
Web mp2kmag.com
mapforums.com