Malcolm Smith
2008-07-04 18:10:49 UTC
I have code which works in BCB5/6 but fails to compile in 2006/2007. I've
changed the code to what I thought was correct, but the data obtained is
invalid (access violations).
The function in question is this:
TMethod __fastcall Nmjfrtti::GetEventMethod( TObject* AObject, const
AnsiString& AEventName )
{
static TTypeKinds AEventType = Typinfo::TTypeKinds() << tkMethod;
Typinfo::PTypeInfo pSourceTypeInfo = reinterpret_cast<PTypeInfo>(
AObject->ClassInfo() );
const int APropCount = Typinfo::GetPropList( pSourceTypeInfo, AEventType,
NULL );
// now we need to populate a property list
TPropList SourcePropList;
#ifdef MJF_BCB10_UP
PPropList pSourcePropList = &SourcePropList;
Typinfo::GetPropList( pSourceTypeInfo, pSourcePropList );
#else
Typinfo::GetPropList( pSourceTypeInfo, AEventType, &(SourcePropList[0]) );
#endif
// make sure the event name actually exists
for( int i = 0; i < APropCount; ++i )
{
Typinfo::PPropInfo NextPropItem = SourcePropList[i];
// make sure we have valid property information
if( NULL == NextPropItem )
continue;
if( AnsiString( NextPropItem->Name ) == AEventName )
return Typinfo::GetMethodProp( AObject, SourcePropList[i] );
}
static TMethod NullMethod = { 0, 0 };
return NullMethod;
}
The code inside the #ifdef MJF_BCB10_UP must be incorrect, but I cannot see
why. At runtime I'm getting invalid addresses for 'NextPropItem', causing
AV's.
What's the correct code for 2006/2007 ?
Thanks in advance.
changed the code to what I thought was correct, but the data obtained is
invalid (access violations).
The function in question is this:
TMethod __fastcall Nmjfrtti::GetEventMethod( TObject* AObject, const
AnsiString& AEventName )
{
static TTypeKinds AEventType = Typinfo::TTypeKinds() << tkMethod;
Typinfo::PTypeInfo pSourceTypeInfo = reinterpret_cast<PTypeInfo>(
AObject->ClassInfo() );
const int APropCount = Typinfo::GetPropList( pSourceTypeInfo, AEventType,
NULL );
// now we need to populate a property list
TPropList SourcePropList;
#ifdef MJF_BCB10_UP
PPropList pSourcePropList = &SourcePropList;
Typinfo::GetPropList( pSourceTypeInfo, pSourcePropList );
#else
Typinfo::GetPropList( pSourceTypeInfo, AEventType, &(SourcePropList[0]) );
#endif
// make sure the event name actually exists
for( int i = 0; i < APropCount; ++i )
{
Typinfo::PPropInfo NextPropItem = SourcePropList[i];
// make sure we have valid property information
if( NULL == NextPropItem )
continue;
if( AnsiString( NextPropItem->Name ) == AEventName )
return Typinfo::GetMethodProp( AObject, SourcePropList[i] );
}
static TMethod NullMethod = { 0, 0 };
return NullMethod;
}
The code inside the #ifdef MJF_BCB10_UP must be incorrect, but I cannot see
why. At runtime I'm getting invalid addresses for 'NextPropItem', causing
AV's.
What's the correct code for 2006/2007 ?
Thanks in advance.
--
Malcolm Smith
MJ Freelancing
http://www.mjfreelancing.com
Associate Editor
C++Builder Developers Journal
http://www.bcbjournal.com
Malcolm Smith
MJ Freelancing
http://www.mjfreelancing.com
Associate Editor
C++Builder Developers Journal
http://www.bcbjournal.com