Search code examples
delphivirtualtreeviewtvirtualstringtree

How to solve this TVirtualStringTree Onheaderclick incompatible parameter?


I tested TVirtualStringTree (version 4.8.7) by Mike Lischke on Delphi 7.0 Windows XP 2. It works fine. I installed the same TVirtualStringTree (v.4.8.7) on another machine (Delphi 7.0 Windows XP 3 system) and tested that same project on the Windows XP 3 system. When I clicked the header, it prompted an error. I removed the TVirtualStringTree (version 4.8.7) from Delphi 7.0 Windows XP 3 and installed a higher version TVirtualStringTree (Version 5.3.0) on Windows XP 3. The same problem still existed.

When I built the project on Windows XP 3, it prompted below:

The vtHeaderClick method referenced by vt.Onheaderclick has an incompatible parameter list. Remove the reference?

I clicked No and run the test program. When I clicked the header, it prompted " Access violation at..."

And it prompted the error below:

function TVTHeader.HandleMessage(var Message: TMessage): Boolean;

// The header gets here the opportunity to handle certain messages before they reach the tree. This is important
// because the tree needs to handle various non-client area messages for the header as well as some dragging/tracking
// events.
// By returning True the message will not be handled further, otherwise the message is then dispatched
// to the proper message handlers.

var
  P: TPoint;
  R: TRect;
  I: TColumnIndex;
  OldPosition: Integer;
  HitIndex: TColumnIndex;
  NewCursor: HCURSOR;
  Button: TMouseButton;
  Menu: TPopupMenu;
  IsInHeader,
  IsHSplitterHit,
  IsVSplitterHit: Boolean;

  //--------------- local function --------------------------------------------

  function HSPlitterHit: Boolean;

  var
    NextCol: TColumnIndex;
    ......
    ......
    case Message.Msg of
          WM_LBUTTONUP:
            with TWMLButtonUp(Message) do
            begin
              if FColumns.FDownIndex > NoColumn then
                FColumns.HandleClick(Point(XPos, YPos), mbLeft, False, False);
             if FStates <> [] then   // this line is highlighted
                FOwner.DoHeaderMouseUp(mbLeft, KeysToShiftState(Keys), XPos, YPos);
            end;
          WM_NCLBUTTONUP:
            with TWMNCLButtonUp(Message) do
            begin

    ......
    ......

How can I solve this?


Solution

  • The method you attached vtHeaderClick has parameters that don't match the required parameters for OnHeaderClick. Because properties defined in the .dfm file are assigned using RTTI, the compiler doesn't get a chance to check that the event handler signature is correct. You only find out at runtime, if you are lucky, with a runtime error.

    Find the declaration of OnHeaderClick in the VTV source and compare the required signature with that of your method. You will see that they do not match. You will then need to change vtHeaderClick to match.

    One way to let the IDE help you out would be to remove the handler for OnHeaderClick in the Object Inspector. Then double click OnHeaderClick and the IDE will generate an event handler stub with the correct signature.

    I don't know what the correct signature is. I could look it up, but then again, so could you. What I'm trying to do with this answer is to show you what went wrong and teach you how to solve the general problem and not just this specific one.