| |

VerySource

 Forgot password?
 Register
Search
View: 3799|Reply: 11

Please master to see what is wrong with the code below, MapX5.0 + VC

[Copy link]

1

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-1-27 00:00:01
| Show all posts |Read mode
void drawNewFeature (
const CString&csLayerName,
double dblLng,
double dblLat,
const CString&csName,
const CString&csLevel,
const CString&csTime
)
{
CMapX * m_mapx;
CMapXStyle pStyle;

pStyle.CreateDispatch (pStyle.GetClsid ());
pStyle.SetSymbolType (miSymbolTypeVector);
pStyle.SetSymbolCharacter (34);
pStyle.SetSymbolVectorSize (16);
pStyle.SetSymbolVectorColor (miColorRed);
Ranch
CMapXLayer pLayer;
pLayer = m_mapx-> GetLayers (). Item (csLayerName);
Ranch
pLayer.BeginAccess (miAccessReadWrite);
Ranch
{
m_mapx-> SetAutoRedraw (FALSE);
pLayer.SetEditable (TRUE);
Ranch
CMapXFeature pFeature;
CMapXPoint pPoint;
CMapXFeatureFactory pFeatureFactory;

pFeatureFactory = m_mapx-> GetFeatureFactory ();
pFeature.CreateDispatch (pFeature.GetClsid ());
pPoint.CreateDispatch (pPoint.GetClsid ());
Ranch
pPoint.Set (dblLng, dblLat);
Ranch
VARIANT vtPoint;
VARIANT vtStyle;
Ranch
vtPoint.vt = VT_DISPATCH;
vtPoint.pdispVal = pPoint.m_lpDispatch;
Ranch
vtStyle.vt = VT_DISPATCH;
vtStyle.pdispVal = pStyle.m_lpDispatch;

pFeature = pFeatureFactory.CreateSymbol (vtPoint, vtStyle);
pLayer.AddFeature (pFeature.m_lpDispatch);

pLayer.Refresh ();

pLayer.SetKeyField ("name");
pFeature.SetKeyValue (csName);
// wrong here
pFeature.Update ();

pLayer.SetKeyField ("level");
pFeature.SetKeyValue (csLevel);
pFeature.Update ();

pLayer.SetKeyField ("time");
pFeature.SetKeyValue (csTime);
pFeature.Update ();

m_mapx-> ZoomTo (1000, pFeature.GetCenterX (), pFeature.GetCenterY ());
Ranch
m_mapx-> SetAutoRedraw (TRUE);
pLayer.SetEditable (FALSE);
Ranch
m_mapx-> Refresh ();
}

pLayer.EndAccess ();
}
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-6-14 16:15:01
| Show all posts
What error is reported?
Put pLayer.AddFeature(pFeature.m_lpDispatch);

pLayer.Refresh();

pLayer.SetKeyField("name");
Move to
pFeature.Update(); Try it later
Reply

Use magic Report

1

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-8-4 23:45:02
| Show all posts
First fix an error:
pLayer.AddFeature(pFeature.m_lpDispatch);
change into:
pFeature = pLayer.AddFeature(pFeature.m_lpDispatch);

I use it in a thread, and I don't know why the problem occurs. The problem is this. Sometimes you can execute this function successfully dozens of times and then there will be problems. Sometimes an error will be reported the first time. The error content is: 0xC0000005: Access Violation.
What I am wondering now is that I have not checked where there are pointers wrong.
Please help.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-7 21:15:01
| Show all posts
It is best to have a small source code that can cause problems, easy to debug, and the problem is intuitive, and it is best to bring data (80% of the problems are caused by data) such a complex code, it is a waste of time to read line by line, not another The head of the compiler
Reply

Use magic Report

1

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-8-10 21:00:01
| Show all posts
Thank you upstairs, but I don't think I need to put all the code and data up, because my problem has been clearly described.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-15 23:30:01
| Show all posts
It seems that you can't add graphic element information like this, you can only add a single attribute with KeyField.
To add multiple properties seems to use CMapXDataset. The landlord look for it, I am not sure about the specifics!
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 Invalid IP Address

Post time: 2020-8-16 16:00:01
| Show all posts
There seems to be a problem in the thread processing
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-18 21:15:01
| Show all posts
Mapx does not seem to support multi-threading. Did you use Mapx for the main thread? If you use it, it may be the problem.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-19 14:45:01
| Show all posts
stand by
Reply

Use magic Report

1

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-8-20 23:15:01
| Show all posts
First of all, I want to thank everyone for your attention to this issue.
Through your tips, I basically know my problem.
It seems to be MapX's question about multithreading.
I want to first consider43471486's suggestions, and then listen to the饭抄蛋andjy666666() suggestions and fix the thread if it doesn't work. I think it should work in the timer of the main thread.
Thank you all, and I hope you will continue to give suggestions.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list