Jump to content
shineworld

DelphiVCL and TreeView OnCollpasing

Recommended Posts

I'm using TreeView and I'm trying to disable the node collapsing with event OnCollapsing(Sender, Node, AllowCollapse).

The Python method is called when a TreeView node is clicked for collapse:

    def TreeViewCollapsing(self, Sender, Node, AllowCollapse):
        AllowCollapse = False

In the event I've set AllowCollapse to False, but in engine code the AllowCollapse := PyObject_IsTrue(LVarParam.Value) = 1; returns True:

procedure TTVCollapsingEventHandler.DoEvent(Sender: TObject; Node: TTreeNode;
  var AllowCollapse: Boolean);
var
  LPyObject, LPyNode, LPyTuple, LPyResult, LPyAllowCollapse: PPyObject;
  LVarParam: TPyDelphiVarParameter;
begin
  Assert(Assigned(PyDelphiWrapper));
  if Assigned(Callable) and PythonOK() then
    with GetPythonEngine() do begin
      LPyObject := PyDelphiWrapper.Wrap(Sender);
      LPyNode := PyDelphiWrapper.Wrap(Node);
      LPyAllowCollapse := CreateVarParam(PyDelphiWrapper, AllowCollapse);
      LVarParam := PythonToDelphi(LPyAllowCollapse) as TPyDelphiVarParameter;
      LPyTuple := PyTuple_New(3);
      PyTuple_SetItem(LPyTuple, 0, LPyObject);
      PyTuple_SetItem(LPyTuple, 1, LPyNode);
      PyTuple_SetItem(LPyTuple, 2, LPyAllowCollapse);
      try
        LPyResult := PyObject_CallObject(Callable, LPyTuple);
        if Assigned(LPyResult) then begin
          Py_DECREF(LPyResult);
          AllowCollapse := PyObject_IsTrue(LVarParam.Value) = 1;
        end;
      finally
        Py_DECREF(LPyTuple);
      end;
      CheckError();
    end;
end;

 

Share this post


Link to post

An user wrote me "AllowCollapse.Value = False" instead of "AllowCollapse = False"....
Work!
Thank you

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×