Board index » cppbuilder » Trigger an Event from a MDIChild...

Trigger an Event from a MDIChild...


2004-06-04 09:34:00 PM
cppbuilder56
Hello all!
How to trigger an custom event for the Main Window from an child window
in an MDI application, when the user prees a button in the child window?
Thenk's for the help!
Eduardo Jauch.
 
 

Re:Trigger an Event from a MDIChild...

Eduardo Jauch wrote:
Quote
How to trigger an custom event for the Main Window from an child window
in an MDI application, when the user prees a button in the child window?
Do you really want to trigger the event or is executing the
eventhandler enough ?
In the latter case just call that eventhandler.
I.e. if you want the eventhandler of a button on your
mainform:
Include the mainforms h file
MainForm->Button1Click ( NULL );
or
MainForm->Button1Click ( Sender );
Hans.
 

Re:Trigger an Event from a MDIChild...

Hans Galema wrote:
i really want to trigger the event, because i need that my application
performe some actions on other child windows... there's some way more
easy to do that?
Eduardo Jauch
 

{smallsort}

Re:Trigger an Event from a MDIChild...

"Eduardo Jauch" < XXXX@XXXXX.COM >wrote in message
Quote
i really want to trigger the event, because i need that my
application performe some actions on other child windows...
there's some way more easy to do that?
Give the child form its own event that the button triggers. Then the main
form assigns an event handler to it when it first creates the child form.
class TChildForm : public TForm
{
__published:
TButton *MyButton;
void __fastcall MyButtonClick(TObject *Sender);
private:
TNotifyEvent FOnDoSomething;
public:
__fastcall TChildForm(TComponent *Owner);
__published;
__property TNotifyEvent OnDoSomething = {read=FOnDoSomething,
write=FOnDoSomething};
};
__fastcall TChildForm::TChildForm(TComponent *Owner)
: TForm(Owner)
{
}
void __fastcall TChildForm::MyButtonClick(TObject *Sender)
{
if( FOnDoSomething )
FOnDoSomething(this);
}
Then you use it like this:
TChildForm *child = new TChildForm(this);
child->OnDoSomething = ChildDidSomething;
void __fastcall TMainForm::ChildDidSomething(TObject *Sender)
{
// do something...
}
Gambit
 

Re:Trigger an Event from a MDIChild...

Thanks Gambit! It's exactly what i need!
Eduardo Jauch!
 

Re:Trigger an Event from a MDIChild...

Eduardo Jauch wrote:
Quote
Hans Galema wrote:

i really want to trigger the event, because i need that my application
performe some actions on other child windows... there's some way more
easy to do that?
Could you please reply in such a way that it is clear who wrote what ?
Now you suddenly have to take actions on other childwindows too ?
Moreover you did not explain why triggering an event would be needed
to act on chilwindows.
Although Remy's solution is a very nice solution, it does
not bring you more than the solution I gave you. What was so
difficult in mines ?
Hans.
 

Re:Trigger an Event from a MDIChild...

"Hans Galema" < XXXX@XXXXX.COM >wrote in message
Quote
Although Remy's solution is a very nice solution, it
does not bring you more than the solution I gave you.
Yes, it does, because my solution is generic enough to work with any kind of
event handler from any type of object that wants to access the child form,
whereas your solution is specific to triggering just the OnClick event of a
specific button on the main form only.
Gambit
 

Re:Trigger an Event from a MDIChild...

Excuse-me Hans, In reality, i misunderstood your solution. I don't know
much about windows programing. On next time that i have a question, or a
doubt, i will try to make my words more precise. i use the button only
as a example, and in fact i use in my software many different childs
that have correlate information that might be updated when something
chang, and this occur not only by user press a button, but too in other
ways, like when he select a combobox for example.
Sorry for my reply, i don't saw that line, i think i erased all of then.
And thanks for the help, i appreciate it. Only i couldn't explain my
problem properly for you.
Eduardo Jauch.
 

Re:Trigger an Event from a MDIChild...

Remy Lebeau (TeamB) wrote:
Quote
>Although Remy's solution is a very nice solution, it
>does not bring you more than the solution I gave you.

Yes, it does, because my solution is generic enough to work with any kind of
event handler from any type of object that wants to access the child form,
Sorry, that may be true, but I was not referring to al kind of
possibilities. Only to what Eduardo asked for. I gave him just
what he asked for.
Quote
whereas your solution is specific to triggering just the OnClick event of a
specific button on the main form only.
My solution does not trigger the OnClick event. It just calls the eventhandler
for that OnClick event. If you would trigger the event then the focus would
change to that button. Where calling an eventhandler of a button does not.
Also with my solution I could call every eventhandler for every type of
object.
Hans.
 

Re:Trigger an Event from a MDIChild...

"Hans Galema" < XXXX@XXXXX.COM >wrote in message
Quote
Sorry, that may be true, but I was not referring to al
kind of possibilities. Only to what Eduardo asked for.
I gave him just what he asked for.
He didn't ask to click the main form's button, though. He asked to trigger
a notification to have the main form to do something when the child form's
button is clicked. Your code doesn't handle that at all.
Quote
My solution does not trigger the OnClick event.
Yes, it does. What do you think MainForm->Button1Click ( NULL ) is actually
doing? Calling Button1's OnClick event handler. That is the same thing as
triggering an event. You don't have to call Click() to trigger an OnClick
event.
Quote
Also with my solution I could call every eventhandler
for every type of object.
The code you showed is specific to a particular button of a particular form
instance. The child form has to have explicit knowledge of the MainForm
data type as well as contain a pointer to the form instance in order to
access the event handler directly. My solution doesn't need to do any of
that. That's he beauty of Borand's __closure extension - you can call a
function withough knowing or caring what type of object, or which object
instance, is attached to it.
Gambit
 

Re:Trigger an Event from a MDIChild...

Remy Lebeau (TeamB) wrote:
Quote
He didn't ask to click the main form's button, though.
In my first reply I asked Eduardo: "Do you really want to trigger
the event or is executing the eventhandler enough ?". He answered
yes. So apparently they are not the same thing for us. For you
they are the same I understand. Well then there lies the difference.
Quote
He asked to trigger
a notification to have the main form to do something when the child form's
button is clicked.
Never saw the word 'notification' in his posts.
Quote
Your code doesn't handle that at all.
My code does exactly the same as what your code does. I call the
eventhandler directly and you call it as callback. The same
function is executed. The same things happen.
Quote
>My solution does not trigger the OnClick event.

Yes, it does.
You did already know what I meant with that. So why this ?
Quote
What do you think MainForm->Button1Click ( NULL ) is actually
doing? Calling Button1's OnClick event handler. That is the same thing as
triggering an event.
Why didn't you come before with this statement ? The opposite was
already in my first reply.
Quote
You don't have to call Click() to trigger an OnClick
event.
For me they are not the same. If you have a TButton you can click on it.
That's when the OnCLick event takes place. If you did not implement an
OnCLick eventhandler then no handler is called. By code you could force
an OnClick to happen. All without an OnClick eventhandler. The button
would get focus. It would look like a real buttonclick.
Quote
>Also with my solution I could call every eventhandler
>for every type of object.

The code you showed is specific to a particular button of a particular form
instance. The child form has to have explicit knowledge of the MainForm
data type as well as contain a pointer to the form instance in order to
access the event handler directly.
That is true;
Quote
My solution doesn't need to do any of
that.
It does. At the moment of assigning the handler already.
Quote
That's he beauty of Borand's __closure extension - you can call a
function withough knowing or caring what type of object, or which object
instance, is attached to it.
At the moment of calling, yes.
Hans.
 

Re:Trigger an Event from a MDIChild...

"Hans Galema" < XXXX@XXXXX.COM >wrote in message
Quote
In my first reply I asked Eduardo: "Do you really want to
trigger the event or is executing the eventhandler enough ?".
He answered yes.
He specifically said that he wanted to trigger an event, not to call the
event handler directly.
Quote
Never saw the word 'notification' in his posts.
Not that particular word specifically, but that is what the intent of his
question was. You have to read "between the lines" sometimes, so to speak.
Quote
My code does exactly the same as what your code does.
Not even close.
Quote
I call the eventhandler directly and you call it as
callback. The same function is executed.
No, it is not. My code is calling a completely different method. Not only
that, but my code is more generic and can be updated dynamically at runtime.
Yours cannot.
Quote
>My solution doesn't need to do any of that.

It does. At the moment of assigning the handler already.
That is done outside the child form, though. The child form is not
assigning its own event handler, someone else is assigning the event handler
to the child form. The child form has no explicit knowledge of the main
form (or any other object) that is being attached to it. Nor does it need
to know.
In any case, I'm tired of debating this. I'm not getting through to you at
all. The original issue has already been long resolved, and this debate
serves no practical purpose anymore. I will not be responding to this
discussion anymore. Its time to move on to other things.
Gambit
 

Re:Trigger an Event from a MDIChild...

Remy Lebeau (TeamB) wrote:
Quote
He specifically said that he wanted to trigger an event, not to call the
event handler directly.
Indeed. But I still have not heard a clear reason why and what
that would bring more.
Quote
You have to read "between the lines" sometimes, so to speak.
So I get my own words back now?
Quote
>I call the eventhandler directly and you call it as
>callback. The same function is executed.

No, it is not. My code is calling a completely different method.
Yes, and that method calls the eventhandler. So the same code
is executed. The result is the same. Please concentrate on this.
Quote
Not only
that, but my code is more generic and can be updated dynamically at runtime.
Yours cannot.
Be happy with that. This is not important in this case. It solely
distracts the attention from the subject.
Quote
In any case, I'm tired of debating this. I'm not getting through to you at
all. The original issue has already been long resolved, and this debate
serves no practical purpose anymore. I will not be responding to this
discussion anymore. Its time to move on to other things.
You have spoken such words before and than the message was cancelled.
You tried to swich the debate to your solution being better. Well
I already said that it was a nice solution. But why try to switch
the subject ?
Your solution does exactly the same as mine. Thats the point.
You just 'forgot' to say that the result is the same. You are
invited to admit that.
Hans.