Udo Weik
2008-03-21 17:53:14 UTC
Hello,
suppose I have a string with the RTTI of an TButton and one event
and want to create that Button during runtime:
object btpTEST_RTTI: TButton
Left = 5
Top = 310
Width = 75
Height = 25
Caption = 'TEST RTTI'
TabOrder = 2
OnClick=cm_TEST_RTTIClick
end
My solution so far:
1. Get the string, create an ASCII-Stream
2. Convert that ASCII-Stream to a BINary-Stream via ObjectTextToBinary( StreamSrc, StreamDst )
3. Create an TReader-Object pReader
4. Assign
pReader->OnFindMethod = FindMethod ;
5. Use pReader->ReadRootComponent() to get the Component
Question: Still looking for an common usable approach,
now creating a new instance of an TButton via code
before:
pButton = new TButton( this ) ;
pButton = (TButton*)pReader->ReadRootComponent( pButton ) ;
pButton->Parent = this ;
Problem: Assigning the Parent (via common approach)
6. For every event OnFindMethod is called:
void __fastcall TfrmAPP_::FindMethod( TReader* Reader, const AnsiString MethodName,
void * &Address, bool &Error )
{
Address = MethodAddress( MethodName ) ;
if ( Address != NULL )
Error = false ;
}
//---------------------------------------------------------------------------
Is that solution correct or is there any better one? I'm wondering why it's
not possible that the events are assigned automatically ('Invalid Property value')?
With TWriter I have sill problems to get the Events streamed, and appart from
that, I don't get the RTTI at all.
pssRTTI_Bin = new TStringStream( "" ) ;
pWriter = new TWriter( pssRTTI_Bin, 4096 ) ;
pWriter->Root = ???
pWriter->WriteComponent( (TComponent*)btpTEST_RTTI ) ???
pssRTTI_Bin is NULL.
Many thanks for any hints and greetings
Udo
suppose I have a string with the RTTI of an TButton and one event
and want to create that Button during runtime:
object btpTEST_RTTI: TButton
Left = 5
Top = 310
Width = 75
Height = 25
Caption = 'TEST RTTI'
TabOrder = 2
OnClick=cm_TEST_RTTIClick
end
My solution so far:
1. Get the string, create an ASCII-Stream
2. Convert that ASCII-Stream to a BINary-Stream via ObjectTextToBinary( StreamSrc, StreamDst )
3. Create an TReader-Object pReader
4. Assign
pReader->OnFindMethod = FindMethod ;
5. Use pReader->ReadRootComponent() to get the Component
Question: Still looking for an common usable approach,
now creating a new instance of an TButton via code
before:
pButton = new TButton( this ) ;
pButton = (TButton*)pReader->ReadRootComponent( pButton ) ;
pButton->Parent = this ;
Problem: Assigning the Parent (via common approach)
6. For every event OnFindMethod is called:
void __fastcall TfrmAPP_::FindMethod( TReader* Reader, const AnsiString MethodName,
void * &Address, bool &Error )
{
Address = MethodAddress( MethodName ) ;
if ( Address != NULL )
Error = false ;
}
//---------------------------------------------------------------------------
Is that solution correct or is there any better one? I'm wondering why it's
not possible that the events are assigned automatically ('Invalid Property value')?
With TWriter I have sill problems to get the Events streamed, and appart from
that, I don't get the RTTI at all.
pssRTTI_Bin = new TStringStream( "" ) ;
pWriter = new TWriter( pssRTTI_Bin, 4096 ) ;
pWriter->Root = ???
pWriter->WriteComponent( (TComponent*)btpTEST_RTTI ) ???
pssRTTI_Bin is NULL.
Many thanks for any hints and greetings
Udo