richard.rowell@gmail.com Guest
|
Posted: Fri Mar 18, 2005 3:50 pm Post subject: Storing a pointer to a TComInterface |
|
|
I want to implement a TTreeView that will allow users to "browse"
objects in a COM component I'm using. I imported the type library, and
all works well, I'm just having problems getting RTTI stuff working. I
store a ptr to the interface pointer in the TTreeNode->Data property
like so:
ITablePtr cdh = tables->get_Item(i);
TTreeNode* cn = TreeView1->Items->AddChild(ntables,cdh->get__Name());
cn->Data = new ITablePtr(cdh);
But when I try to check the RTTI in the onExpanding event of the
TTreeNode, I run into problems...
void __fastcall TForm1::TreeView1Expanding(TObject *Sender,
TTreeNode *Node, bool &AllowExpansion)
{
ITablePtr* tptr;
void* data = Node->Data;
tptr = dynamic_cast< ITablePtr* >( data );
}
This will not compile, it dies on the dynamic cast line:
[C++ Error] Unit1.cpp(166): E2307 Type 'void' is not a defined class
with virtual functions
I'm guessing this has something to do with ITablePtr being a generated
interface:
typedef TComInterface<ITable, &DIID_ITable> ITablePtr;
Different nodes will store different types of objects, so I need the
RTTI to determine the type of the object. I guess I could just store
the IDispatch in a wrapper and re-construct the ITablePtr later on, but
I'm hoping to avoid that...
Thanks in advance!
|
|