Discussion:
BDS2006: TReader, TWriter and Event-Management
(too old to reply)
Udo Weik
2008-03-21 17:53:14 UTC
Permalink
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
Remy Lebeau (TeamB)
2008-03-21 18:52:05 UTC
Permalink
Post by Udo Weik
Question: Still looking for an common usable approach,
now creating a new instance of an TButton via code
pButton = new TButton( this ) ;
pButton = (TButton*)pReader->ReadRootComponent( pButton ) ;
pButton->Parent = this ;
Problem: Assigning the Parent (via common approach)
What exactly is the problem? You only have 1 component in the DFM text. It
has no reference to determine a Parent automatically, so you have to do it
manually, as you already are.
Post by Udo Weik
I'm wondering why it's not possible that the events are assigned
automatically ('Invalid Property value')?
Again, because there is nothing in the DFM text for the reader to know where
to look when resolving the method references. Which is why the OnFindMethod
event exists - so you can do the lookup yourself when needed.
Post by Udo Weik
With TWriter I have sill problems to get the Events streamed,
and appart from that, I don't get the RTTI at all.
Have you tried using the TStream::WriteComponent() method instead of using
TWriter directly?

pssRTTI_Bin->WriteComponent(btpTEST_RTTI);


Gambit
Udo Weik
2008-03-21 19:44:57 UTC
Permalink
Hello Remy,

thanks again for your answer and happy easter!
Post by Remy Lebeau (TeamB)
Post by Udo Weik
Question: Still looking for an common usable approach,
now creating a new instance of an TButton via code
pButton = new TButton( this ) ;
pButton = (TButton*)pReader->ReadRootComponent( pButton ) ;
pButton->Parent = this ;
Problem: Assigning the Parent (via common approach)
What exactly is the problem? You only have 1 component in the DFM text. It
has no reference to determine a Parent automatically, so you have to do it
manually, as you already are.
Of course I'm loading different components. So the common approach is to
use a TComponent-Object. But how can I determine whether it's an TControl
for assigning the Parent? dynamic_cast<>()?
Post by Remy Lebeau (TeamB)
Post by Udo Weik
I'm wondering why it's not possible that the events are assigned
automatically ('Invalid Property value')?
Again, because there is nothing in the DFM text for the reader to know where
to look when resolving the method references. Which is why the OnFindMethod
event exists - so you can do the lookup yourself when needed.
O. k.!
Post by Remy Lebeau (TeamB)
Post by Udo Weik
With TWriter I have sill problems to get the Events streamed,
and appart from that, I don't get the RTTI at all.
Have you tried using the TStream::WriteComponent() method instead of using
TWriter directly?
pssRTTI_Bin->WriteComponent(btpTEST_RTTI);
Done so before using TWriter, that works. But why does TWriter not work?
And how can I stream the events?


Thanks and greetyings
Udo
Remy Lebeau (TeamB)
2008-03-24 16:41:38 UTC
Permalink
Post by Udo Weik
Of course I'm loading different components. So the common approach
is to use a TComponent-Object. But how can I determine whether
it's an TControl for assigning the Parent? dynamic_cast<>()?
Yes.


Gambit
Udo Weik
2008-03-25 00:15:29 UTC
Permalink
With TWriter ... and appart from that, I don't get the RTTI at all.
A new TWriter-Instance is created with an already created Stream:
pWriter = new TWriter( pStream, 2048 ) ;

The solution is that the TWriter-Instance must be deleted after
streaming the component:
pWriter->WriteRootComponent( ... ) ;
delete pWriter ;
Then pStream is filled with the RTTI.


Greetings
Udo

Loading...