Forum Discussion

markus_humm's avatar
markus_humm
Occasional Contributor
15 years ago

Clicking on items of a TVirtualTreeView in Delphi script

Hello,



I'm uising TC 8.1 and Delphi script. I want to click on a line of my TVirtualTreeView.

I can read out the nodes, but how to click on a certain line?

(the application is compiled open enough to be able to work properly with the VST)



I'd liek to write a routine like this:



function ClickLine(vst, line);

begin

  // code to go to the desired line and get its node

  // that's easy and should work

end;



But how to click on the line after getting its node?



Greetings



Markus

1 Reply


  • Hello Markus,





    Here is an example:







    procedure ClickItem(vst, row, col);

    var i, X, Y: Integer;

        text: String;

        node: OleObject;

    begin  

      i := 0;                                                                            

      X := vst.Header.Columns.Items(col).Left + 25;

      Y := 0;

      

      node := vst.GetFirst(false);

      

      while (aqObject.IsSupported(node, 'InstancePtr')) do

      begin    

        if (i = row) then

        begin

          Y := Y + node.TotalHeight/2;

          break;

        end;

          

        Y := Y + node.TotalHeight;

        i := i + 1;

        node := vst.GetNext(node, false);

      end;

      

      node := vst.GetNodeAt(X, Y);

       

      if (aqObject.IsSupported(node, 'InstancePtr')) then

      begin

        text := vst.GetText(node, col);

        Y := Y + vst.Header.Height;

        

        Log.LockEvents;

        vst.Click(X, Y);

        Log.UnlockEvents;

        

        Log.Event('The "' + text + '" node was clicked.');    

      end;

    end;





    procedure ClickLine(vst, line);

    begin

      ClickItem(vst, line, 0); 

    end;





    procedure Test();

    var vst: OleObject;

    begin  

      vst := {...};

      ClickItem(vst, 12, 3);

      // ...  

      ClickLine(vst, 4);

      // ...  

    end;