Message quirks

If i make a derived class from base class "Message", how am I supposed to interact with it inside of the 'handleMessage() callback?  

It seems that dynamic_cast<> is the only way, yes?  

class DerivedClassFromMessage : public Message {
  DerivedClassFromMessage() {}
  ~DerivedClassFromMessage() {}
  int a;
  int b;

//somewhere in my code..
postMessage( new DerivedClassFromMessage() );

void handleMessage( const Message &message ) {
//what to do if we pass in a subclass of "Message"?


I wish the Message, MessageListener, and MessageCallback classes all had examples in their documentation.   Can you provide one? 


But in most cases it's easier to use a CallbackMessage - just grep the codebase for many examples of that.

I'm hoping to find a means to communicate between parent components and child components, seeing as child components can't be given pointers to their parent component.  


if I have my MainContentComponent, and I addAndMakeVisible() another component class (let's call it ChildComponentContent), what's the proper means of sending messages between the two?   


For example, if you click on a button inside ChildContentComponent, how would you send a special message to MainContentComponent to do something?   such as inserting a chunk of audio into an audio buffer each time you press this button in the child component, for example.   the MainContentComponent is gonna handle all things audio related, but you might have a bunch of different buttons inside multiple child components, and each of them needs to send a message to MainContentComponent to insert a chunk of audio (stored in the message) into the audio buffer.  


I'm using audio chunks as an example.  please don't get tied up with "audio needs to be given a timestamp, you gotta lock threads, etc..".    This is strictly about how to have a child component send a message to a parent component. 

I guess to summarize what I'm hoping to learn how to do:


in my child class: 

mainContentComponent->postMessage( theMessage );

to talk to the parent class

and in the parent class to talk to the child:

childContentComponent->postMessage( theMessage );

Yet, it seems impossible to populate the childContentComponent with a member pointer variable that points to the parent without failing to compile.  


Even better would be to do something like :

postMessage( new TargetedMessage( "someTarget", messageData ) );

and then every component that subclasses MessageListener() could receive that message, and their internal handleMessage() would decide if they should do something to it.  




how is this even helpful?   Why would I want to send a message to myself? 

void MessageListener::postMessage (Message* const message) const
    message->recipient = const_cast <MessageListener*> (this);

Well you might be busy doing something important and want to send a message reminding you to do something less important some time in future when you're less busy.