example “virtual treeview” IterateSubtree in C++Builder XE-XE7

有些话、适合烂在心里 提交于 2020-01-07 22:59:35

问题


I need an example how to use "virtual treeview" IterateSubtree in C++ Embarcadero Xe1-7.

I have the problem with this code:

void __fastcall TMyForm::BuSearchClick(TObject *)
{
  MyTreeView->IterateSubtree(NULL, SearchDataSomeId, (void*)&PNodeData, TVirtualNodeStates(), false, false);
}

void __fastcall TMyForm::SearchDataSomeId(TBaseVirtualTree*, PVirtualNode Node, void *Data, bool &Abort)
{
}

The compiler gives the following error:

[bcc32 Error] MyFile.cpp(363): E2034 Cannot convert 'void (_fastcall * (_closure )(TBaseVirtualTree *,TVirtualNode *,void *,bool &))(TBaseVirtualTree *,TVirtualNode *,void *,bool &)' to '_di_TVTGetNodeProc'

回答1:


You're trying to use what Delphi/C++Builder calls a method pointer or __closure. Virtual Treeview expects an anonymous method. See here for more details.

I think that creating an anonymous method in C++Builder involves subclassing from TProc and implementing the Invoke method, but it seems to be very poorly documented.

If subclassing TProc doesn't work or is too hard to figure out, I can think of a couple of options:

  • Hack the Virtual Treeview source to create an IterateSubtree overload taking a method pointer.
  • Ask a new question on Stack Overflow in hopes that someone else knows how to create a Delphi anonymous method in C++Builder.



回答2:


thanks very much`

i have found the solution

typedef void (*TIterateSubtreeCallBack)(TBaseVirtualTree*, PVirtualNode Node, void *_Data, bool &Abort);   

class TMyVTGetNodeProcRef : public TCppInterfacedObject<TVTGetNodeProc>    
{
private:   
  TIterateSubtreeCallBack callback;   
public:   
  TMyVTGetNodeProcRef(TIterateSubtreeCallBack _callback) : callback(_callback) {}    
  INTFOBJECT_IMPL_IUNKNOWN(TInterfacedObject);   

  void __fastcall Invoke(TBaseVirtualTree* Sender, TVirtualNode *Node, void *Data, bool &Abort)   
  {   
    return callback(Sender, Node, Data, Abort);   
  }   
};   

void __fastcall TMyForm::BuSearchClick(TObject *)   
{   
  Node= MyTreeView->IterateSubtree(NULL, new TMyVTGetNodeProcRef(SearchDataId), (void*)&PNodeData, TVirtualNodeStates(), false, false);   
}   

void TMyForm::SearchDataId(TBaseVirtualTree*Tr, PVirtualNode Node, void *_Data, bool &Abort)   
{   
 put my code ...   
}   
//---------------------------------------------------------------------------


来源:https://stackoverflow.com/questions/29901427/example-virtual-treeview-iteratesubtree-in-cbuilder-xe-xe7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!