Shape editor is not attached to a map

Hello! I want to use ShapeEditor class to edit Shape (AddPoint, Edit vertices, Delete points), when call StarEdit() function, report error :Shape editor is not attached to a map
I don’t know how to attach a map, I didn’t find the attach method. This is my code:

m_sf->CreateNewWithShapeID("", ShpfileType::SHP_POLYGON);

m_LineHandle = m_map->AddLayer(m_sf, true);
VARIANT_BOOL b = m_se->StartEdit(m_LineHandle, 0);
long err = m_se->GetLastErrorCode();
CString estr = m_se->GetErrorMsg(err);

Hello @zcwbnu

You don’t need to create a ShapeEditor. You should get a reference to the one that’s already built in to the map.

" Each AxMap control has a single instance of shape editor associated with it available by AxMap.ShapeEditor property."


Thank you @ jerryfaust . I see the AxMap.ShapeEditor property in the AxMap Class specification, However my map file is generated by OCX, and I don’t find the getShapeEditor function.

I found an older program in which I generated the interface using the Class Wizard. Sometimes the wizard doesn’t generate all available methods, and I don’t know why (perhaps when they are defined as LPDISPATCH instead of the specific type, which in this case is IShapeEditor). But they can usually be added manually.

I found these various references (from various files):

within the OCX:

dispidShapeEditor = 235L,

afx_msg IShapeEditor* GetShapeEditor(void);

DISP_PROPERTY_EX_ID(CMapView, "ShapeEditor", dispidShapeEditor, GetShapeEditor, SetNotSupported, VT_DISPATCH)

in the calling program:

LPDISPATCH * GetShapeEditor()
    LPDISPATCH * result;
    GetProperty(0xeb, VT_DISPATCH, (void*)&result);
    return result;

I hope this is helpful. For the work you’re doing, I would encourage you to download the source code for the OCX. In it, you can see the baseline definitions in the IDL file, and the source code used to attach to the methods.


Thank you very much@jerryfaust ,it works.