Link to home
Start Free TrialLog in
Avatar of Delphi_developer
Delphi_developer

asked on

Override procedure from Virtual Treeview

Hi

I did a little change in Virtual Treeview code. I enabled Selection with Alt key. It seems that this was disabled for some reason. I need my Treeview to be able to select nodes with Alt key.

So, I just commented these rows:

if ssAlt in ShiftState then
    begin
      AltPressed := True;
      // Remove the Alt key from the shift state. It is not meaningful there.
      Exclude(ShiftState, ssAlt);
    end
    else
      AltPressed := False;

Open in new window


to

if ssAlt in ShiftState then
    begin
    // Commented next 3 lines to enable Selecting rows with Alt key - this code was disabling select with Alt
(*      AltPressed := True;
      // Remove the Alt key from the shift state. It is not meaningful there.
      Exclude(ShiftState, ssAlt);*)
    end
    else
      AltPressed := False;

Open in new window



It works fine.

Now, I was thinking to override (have a new code in my unit) the whole procedure
procedure TBaseVirtualTree.HandleMouseDown(var Message: TWMMouse; var HitInfo: THitInfo);

Open in new window

so I don't change the original code. This way I don't loose my changes when upgrading to new version of VirtualTreeview from my current 4.8.6.

How can I do this?
The definition is in VirtualTrees.pas, in protected part of TBaseVirtualTree
TBaseVirtualTree = class(TCustomControl)
...
protected
...
procedure HandleMouseDown(var Message: TWMMouse; var HitInfo: THitInfo); virtual;

Open in new window



Thank you for advice!
Avatar of Ephraim Wangoya
Ephraim Wangoya
Flag of United States of America image

Two ways to do it
1. Create a new unit and register the new component in your delphi components
    unit CustomVitualTree;
    implementation
    type
      TMyBaseVirtualTree = class(TCustomControl)
       protected
       procedure HandleMouseDown(var Message: TWMMouse; var HitInfo: THitInfo); override;
     end;

2. In the unit where you are using the Virtual tree, just before the declaration of the Form type. But this is only available to your current form where the VirtualTree object is used

type
TBaseVirtualTree = class(VirtualTrees.TBaseVirtualTree)
protected
  procedure HandleMouseDown(var Message: TWMMouse; var HitInfo: THitInfo); override;
end;

//Your current code
TYourForm = class(TForm)
 ....
end;
SOLUTION
Avatar of sarabande
sarabande
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Delphi_developer
Delphi_developer

ASKER

@ewangoya:
thank you, and where and how do I put the procedure code? I tried just copy&paste the whole HandleMouseDown procedure to main unit, but gives errors on 'Undeclared identifier' for some properties of TBaseVirtualTree defined in original unit (VirtualTrees.pas).

Suggestion?

Edit: I use suggestion #2.
For the members that are not known, try and look for the public or protected propertis that access those members. For example, it the error is undeclared identifier FStates, then there is a property TreeStates that accesses FStates. Replace every occurence of FStates with TreeStates.

You may encounter undeclared procedure or function, in such a case, you have to reimplement the procedure in your class
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you, but this is too complicated, I thought it would be much easier - just a definition and new code. Let me play with it and get back to you.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
why is my solution difficult? You changed source anyway. So just put this modified file in folder where your project is and this is it. Delphi IDE will do the rest.
Oh, I didn't see your comment at all! It is interesting and easy, but how would it work when source has some other units that relies on?

Now I have all components in different folders in delphi\lib folder. So, virtual treeview has all it's files in delphi\lib\VTVSource folder. So, if I change something and wne I overwrite with incorrect source versoin, I just copy full folder from backup.

If I put just changed file into my app folder, then it is not only to take of this file, but also the whole source folder, since it may rely on files that I didn't change and are different than the new source. Right?

And if I have my system in place, its easier to maintain 'the list' of all files I changed, since I 'don't really need a list' as all changed files are 'connected' in my
ValidateSourceFiles

Open in new window

procedure, which validates for all variables in source files.

I'm not saying your suggestion is not good, just not that practical.

Right?
No, you don't need to copy the whole folder, just changed file. This is "the big" thing. Delphi IDE will use this file instead of original (where component is installed) and use other
(depending) files from original folder. Main problem is if you change versions of original component often. Then you will need to make changes one time more or create inherited class at least.
I understand you, completely. That is why I decided my suggestion is best for me. In your case if I don't copy the file in my new folder (new project, rebuilding old project, upgrading Delphi version, etc.), ti will take the original source even if it shouldn't, because I have no 'security' measure implemented.

In my case, as soon as I don't have the correct file in my 'path' I will know. This way I know there is only one source of files, the appropriate folder and not something here something there. This is actually gonna solve some of my dilemmas I had before, when I had installed multiple versions of same component and when new system installation was done, I had to figure out which of the files I was actually using.

You see my point?
Yes. I show you as I did before. This is common when do changes (fixes) on original delphi source. This way I only backup my projects (folders). When reinstall delphi or some component - I don't bother with changes once more.
Thank you all for your suggestions, I decided my answer is best choice and assigned points for trying and steering me into my direction.