Hello cluster,
There is really sophisticated situation with these notifications. I think it is because creating connection is complex action. First XTP_FGN_CONNECTIONCHANGED notification is about creation temporary Connection object pDragConnection (method CXTPFlowGraphControl::StartDragConnectionPoint), which will be deleted at the end of method if end point (InputPoint) is empty.
To allow your algorithm works (prevent even starting of creation new connection) and to correct handling canceling in notification we need to add handling "*pResult = -1" in StartDragConnectionPoint(). One of way is checking CXTPFlowGraphConnection::m_nConnectionIndex of new connection or other member CXTPFlowGraphConnection::m_pPage with public getter GetPage().
void CXTPFlowGraphControl::StartDragConnectionPoint(CXTPFlowGraphConnectionPoint* pPoint){ .... CXTPFlowGraphConnection* pDragConnection = new CXTPFlowGraphConnection(); pDragConnection->SetOutputPoint(pOutputPoint);
m_pActivePage->GetConnections()->AddConnection(pDragConnection);
//adding connection was canceled through notification if (pDragConnection->m_nConnectionIndex == -1 || pDragConnection->GetPage() == NULL) { pDragConnection->OnRemoved(); pDragConnection->InternalRelease(); return; } .... |
Such conditions should be added in CXTPFlowGraphUndoDeleteConnectionCommand::Undo
void CXTPFlowGraphUndoDeleteConnectionCommand::Undo(){ ...... m_pPage->GetConnections()->AddConnection(m_pConnection); //adding connection was canceled through notification if (m_pConnection->GetPage() == NULL) { m_pConnection->OnRemoved(); m_pConnection->InternalRelease(); return; } } } |
The reason of assertions in CXTPFlowGraphConnectionPoint::OnRemoved() is because you don't allow addition new connection in AddConnection() but then you call SetInputPoint() or SetOutputPoint()
CXTPFlowGraphConnection* pConnection; pConnection = pPage->GetConnections()->AddConnection(new CXTPFlowGraphConnection()); pConnection->SetOutputPoint(pTableOrders->GetConnectionPoints()->FindConnectionPoint(_T("Customer ID"))); pConnection->SetInputPoint(pTableCustomers->GetConnectionPoints()->FindConnectionPoint(_T("ID"))); |
in such code should be added checking results of AddConnection()
CXTPFlowGraphConnection* pConnection; pConnection = pPage->GetConnections()->AddConnection(new CXTPFlowGraphConnection()); if (pConnection->GetPage() == NULL) //adding connection was canceled through notification { //pConnection->OnRemoved(); pConnection->InternalRelease(); pConnection = NULL; } else { pConnection->SetOutputPoint(pTableOrders->GetConnectionPoints()->FindConnectionPoint(_T("Customer ID"))); pConnection->SetInputPoint(pTableCustomers->GetConnectionPoints()->FindConnectionPoint(_T("ID"))); } |
Regards, Oleksandr Lebed
|