title: Click on TListView (on TForm) over TTreeView triggers TTreeView OnChange event
body: <p>Using Borland C++ Builder</p>
  
  <p>I have an application with a self created Breadcrumb control, positioned just above a <code>TTreeView</code> control, with <code>TListView</code> controls (<code>alClient</code> inside <code>TForms</code>) as dropdown menus.</p>
  
  <p><a href="https://i.stack.imgur.com/TRXNH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TRXNH.png" alt="enter image description here"></a></p>
  
  <p>The position of the controls is new.  Meaning, the implementation is older, and worked perfectly before, but I have only just moved the breadcrumb control above the <code>TTreeView</code> control.</p>
  
  <p>And I now notice that a click on a <code>TListView</code> Item from the breadcrumb control, <strong>also</strong> triggers the <code>TTreeView</code> <code>OnChange</code> event !
  And the selected node is the top node.</p>
  
  <p>This causes a conflict in my design as both events, the <code>TListView</code> item click and the <code>TTreeView</code> <code>Onchange</code> cause different things to be displayed/done.
  It's also not 100% which event ultimately 'wins' so the result is variable as well.</p>
  
  <p>I can look into trying to disable <code>TTreeView</code> while the breadcrumb code is executing, so that the click is ignored, but I wonder if this is normal or if I'm missing something ?</p>
  
  <p>Is it normal that both controls trigger when displayed over each other ?</p>
  
  <p>The ListView item click is processed via the OnClick event that is assigned following function:</p>
  
  <pre><code>void __fastcall TBreadcrumbListViewEx::InternalListViewClick(TObject *Sender)
  {
  
  if (FListView-&gt;Selected &amp;&amp; FOnBreadcrumbListItemClick)
      {
      TPoint pt;
      pt = FListView-&gt;ScreenToClient(Mouse-&gt;CursorPos);
  
      THitTests HitTests = FListView-&gt;GetHitTestInfoAt(pt.x, pt.y);
      if ( (HitTests.Contains(htOnIcon)) || (HitTests.Contains(htOnItem)) ||
           (HitTests.Contains(htOnLabel)) || (HitTests.Contains(htOnStateIcon)) )
          {
          // This is a very precarious situation, because the FOnBreadcrumbListItemClick callback will most likely trigger building a new Breadcrumbs layout (Different Items)
          // Which causes OnData events from this control to want to access Breadcrumbs that have been deleted already
          // Therefore, get the selected Item (which will trigger OnData) and use its Index and Data members
  
          TListItem *Item = FListView-&gt;Selected ;
  
          // Next prevent any OnData event to get through and wreak havoc
          // This needs to be done *before* Hide() is called
  
          _releasing = true ;
  
          // Hide is necesary because if the FOnBreadcrumbListItemClick event takes a long time, for instance it shows a dialog,
          // this control will still be visible, yet it cannot show proper content anymore, since the OnData event is disabled
          // Hence Hide() to no show it anymore when, for instance, a dialog is showing
  
          Hide() ;
  
          FOnBreadcrumbListItemClick(this, Item-&gt;Index, BreadcrumbItem, Item-&gt;Data);
  
          Release(); // Close();
          }
      }
  
  }
  </code></pre>
  
  <p>I have been running tests.
  First I disabled the event/callback <code>FOnBreadcrumbListItemClick()</code> but the problem persists, even though nothing really happens when the item is clicked.
  I have been playing with disabling <code>Hide()</code>, <code>Release()</code>, replaced <code>Release()</code> with <code>Close()</code> etc.  But the problem persists if one of them is still in place.</p>
  
  <p>Only when I disable both <code>Hide()</code> and <code>Release()</code>/<code>Close()</code> as well I seem not to get into trouble.  Only then I did not see the <code>TTreeView</code> <code>OnChange</code> occur anymore in my testing.  To be honest I'm not sure of anything anymore at this point.</p>
  
  <p>Is this what you would expect ?  Or is this merely a side effect and the problem is still something else ?</p>
  
  <p>Also ... how the hec am I going to be able to execute the callback and Hide/Remove the popup from view, without 'upsetting' <code>TTreeView</code> ?</p>
  
  <p>Disabling <code>TTreeView</code> temporarily is still an option but I'd rather fix this right, not to get into trouble again next time I move the controls to a different position.</p>