0

I have seen an example in Stackoverflow submitted by H.K link: example "virtual treeview" IterateSubtree in C ++ Xe1-7

See sample code from answer submitted by H.K at the bottom of this question . The problem I am having is using it in my Builder C++ XE application. I am using it by calling this method to pass the Method "NodeTypeFinder". Note my methods uses VTree as the name I have given to the VirtualTreeview component - different to H.K's examples. The interface I have written has this change and is essentially the same a H.K's example.

My FindData Method.

VirtualNode __fastcall TfrmMain::findData(PVirtualNode n, String title, int id)
{
  // The result of the IterateSubtree call is the node which caused the
  // callback method to Abort.  See method NodeTypeFinder for detail on the
  // Abort conditions.
  PVirtualNode SearchNode = NULL;
  TVirtualNodeStates nStates;
  rec r;

  r.Caption = title;
  r.ID = id;
  nStates =  TVirtualNodeStates() << vsInitialized;

  SearchNode = VTree->IterateSubtree(n, new TMyVTGetNodeProcRef(NodeTypeFinder), (void*) &r, nStates, false, false);


  //SearchNode = VTree->IterateSubtree(n, NodeTypeFinder,
  //                                            (void*) &r, nStates, false, false);

  return SearchNode;
}

The Callback method is below 'NodeTypeFinder'

//---------------------------------------------------------------------------
void  __fastcall TfrmMain::NodeTypeFinder(TBaseVirtualTree *Sender,
 PVirtualNode Node, void* Data, bool &Abort)
{
  // Used to abort the findData method, if criteria is true.
  // Used in conjunction with method findData.
  Abort = ((rec*) Sender->GetNodeData(Node))->Caption == ((rec*) Data)->Caption
       && ((rec*) Sender->GetNodeData(Node))->ID == ((rec*) Data)->ID;
}
//---------------------------------------------------------------------------

My issue is that my compiler is giving the following error:

[BCC32 Error] Main.cpp(669): E2235 Member function must be called or its address taken
  Full parser context
    Main.cpp(657): parsing: TVirtualNode * _fastcall TfrmMain::findData(TVirtualNode *,UnicodeString,int) 

So could I please get some advice on how do I overcome this error? I have tried everything I can think of - checked the Delphi hpp files for virtualtreeview and all the on line help. I have applied all the patches/updates to Rad Studio XE.

Thanks Daryl

H.K's interface code and example methods.

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 ...   
}   
Daryl
  • 1
  • Where and how are you calling `findData()`? It is hard to tell whether the error is on `findData()` itself, or on something `findData()` is doing. Also, is `NodeTypeFinder` declared as `static`? If not, it needs to be, since `TIterateSubtreeCallBack` does not use `__closure`. And you need to drop `__fastcall` from `NodeTypeFinder`. And try `&NodeTypeFinder` when constructing the `TMyVTGetNodeProcRef` object – Remy Lebeau Jan 11 '19 at 09:10
  • Remy - your advice was the solution. Once I made the method `NodeTypeFinder` static and removed `__fastcall` everything worked as expected. Thanks for your assistance. – Daryl Jan 11 '19 at 22:14

0 Answers0