Question

I have a popup menu which works as expected. The drag-and-drop functionality on the same object works as expected. Put them together, and...

The popup menu appears when I right-click. Wile the menu is stil there, a subsequent left-click off the popup menu but still on the object invokes the drag-and-drop functionality, as if the initial right-click were a left click which had been held until now and then released.

void __fastcall myGrid::eDragDrop(System::TObject *Sender, System::TObject *Source, int X, int Y)
{
  while((Sender != this) && (Sender != NULL))
  {
    TControl *control = dynamic_cast < TControl * > (Sender);
    if(control != NULL)
    {
      X += control->Left;
      Y += control->Top;
      Sender = control->Parent;
    }
    else
    {
      Sender = NULL;
    }
  } // while
  // Check for a drop onto the Chart

  if((Column != NULL)&&(Column->Visible)&& (Column->HeaderIndex>=0))
  {
    int Xt = X - FHeaderSB->Left + FHorzScroll->Position;
    int HeaderIndex = Column->HeaderIndex;
    if((Xt > FHeaderSections->Items[HeaderIndex]->Left) && (Xt < FHeaderSections->Items[HeaderIndex]- >Right))
    {
      Xt -= FHeaderSections->Items[HeaderIndex]->Left;
      GotDragDropTime = true;
      DragDropTime = Column->GetTimeFromPosition(Xt);
    } // if
  } // if Visible


  if(fDragDrop != NULL)
  {
    fDragDrop(Sender, Source, X, Y);
  }
}

What have I done wrong? How can I fix this?

Was it helpful?

Solution

Found it! There was an oversight in a function called in OnMouseDown where the PendingDrag flag was set without checking which button was clicked.

I hadn't realised how much of the drag functionality was controlled in our code. It was not the fault of Borland C++ Builder 6 after all.

Thank you for the insightful comments. They helped me find the bug.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top