| View previous topic :: View next topic |
| Author |
Message |
MAC Guest
|
Posted: Wed Feb 28, 2007 11:43 pm Post subject: Accessing Main methods in Child Window |
|
|
Ok Maybe you not allowed to do this, Im not too clued up with borland, but I
want to know how you access methods in your main form from a MDIchild.
Application->Mainform gives me non of the methods that actually belong to my
main form. I have a child window that displays images. And I have another
form a "color selector" that displays the color that your mouse is over on
the child form. Now the "color selector" that shows the "zoomed" color is
accessible to the main form and not the child. Also the "color selector" has
a Updown button to increase and decrease the intensity of the color that
you selected. So in the mainform I have methods to acess the calls i need to
"color selector" to change color etc. So I just need a way to access the
mainform from the child's mousemove method.
Any help will be appreciated.
Thanks |
|
| Back to top |
|
 |
Kent Guest
|
Posted: Thu Mar 01, 2007 3:31 am Post subject: Re: Accessing Main methods in Child Window |
|
|
| Quote: | want to know how you access methods in your main form from a
MDIchild. |
In the child's cpp unit include "mainform.h".
| Quote: | "color selector" to change color etc. So I just need a way to access
the
mainform from the child's mousemove method.
|
In mousemove, call "mainform->methodname". |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Thu Mar 01, 2007 3:35 am Post subject: Re: Accessing Main methods in Child Window |
|
|
"MAC" <none (AT) none (DOT) com> wrote in message
news:45e5bfb2 (AT) newsgroups (DOT) borland.com...
| Quote: | Ok Maybe you not allowed to do this
|
Sure, you are.
| Quote: | I want to know how you access methods in your main form from a
MDIchild. |
Simply include the main form's header file in the child's source file,
and then use the main form's global pointer to access it when needed.
| Quote: | Application->Mainform gives me non of the methods that actually
belong to my
main form.
|
That is because the MainForm property is declared as a generic TForm
pointer, but your methods are specific to your descendant form class.
You could use the MainForm property, but you would have to type-cast
the pointer in order to access your methods.
Gambit |
|
| Back to top |
|
 |
MAC Guest
|
Posted: Thu Mar 01, 2007 3:37 am Post subject: Re: Accessing Main methods in Child Window |
|
|
I tried that already and it gives me errors everything to do with my
children in the main form. I think it is circular referencing.
"Kent" <kentav (AT) accessus (DOT) net> wrote in message
news:45e5f4b0 (AT) newsgroups (DOT) borland.com...
| Quote: |
want to know how you access methods in your main form from a
MDIchild.
In the child's cpp unit include "mainform.h".
"color selector" to change color etc. So I just need a way to access
the
mainform from the child's mousemove method.
In mousemove, call "mainform->methodname".
|
|
|
| Back to top |
|
 |
MAC Guest
|
Posted: Thu Mar 01, 2007 3:43 am Post subject: Re: Accessing Main methods in Child Window |
|
|
I tried to include and it gives me an error on this line for example.
This method is in my MainForm.
TMDIChild *__fastcall GetChild( AnsiString Name ); //error is type name
expected
and my child class is defined as
class TMDIChild : public TForm
{
//methods here
}
now if I dont include the header file of the main form in my child, no
errors. Can anyone explain.
"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote in message
news:45e5f5d1$1 (AT) newsgroups (DOT) borland.com...
| Quote: |
"MAC" <none (AT) none (DOT) com> wrote in message
news:45e5bfb2 (AT) newsgroups (DOT) borland.com...
Ok Maybe you not allowed to do this
Sure, you are.
I want to know how you access methods in your main form from a
MDIchild.
Simply include the main form's header file in the child's source file,
and then use the main form's global pointer to access it when needed.
Application->Mainform gives me non of the methods that actually
belong to my
main form.
That is because the MainForm property is declared as a generic TForm
pointer, but your methods are specific to your descendant form class.
You could use the MainForm property, but you would have to type-cast
the pointer in order to access your methods.
Gambit
|
|
|
| Back to top |
|
 |
MAC Guest
|
Posted: Thu Mar 01, 2007 4:09 am Post subject: Re: Accessing Main methods in Child Window |
|
|
To add to that I also have the following at the end of the Mainform class
defintion.
extern TMainForm *MainForm;
extern TMDIChild *__fastcall MDIChildCreate(void);
This is done automatically by borland. |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Thu Mar 01, 2007 5:23 am Post subject: Re: Accessing Main methods in Child Window |
|
|
"MAC" <none (AT) none (DOT) com> wrote in message
news:45e5f77a (AT) newsgroups (DOT) borland.com...
| Quote: | I tried to include and it gives me an error on this line for
example. |
You have a circular reference issue, where the header guards are
getting in your way. One of the header files is getting included a
second time, and its guards are causing the header's types to get
skipped. You will need to use forward declarations, ie:
--- MainForm.h ---
class TMDIChild; // forward declaration
class TMainForm : public TForm
{
private:
//...
TMDIChild*__fastcall GetChild(AnsiString Name);
//...
};
--- MainForm.cpp ---
#include "MDIChild.h"
TMDIChild*__fastcall TMainForm::GetChild(AnsiString Name)
{
//...
}
--- MDIChild.cpp ---
#include "MainForm.h"
void __fastcall TMDIChild::DoSomething()
{
MainForm->...;
}
Gambit |
|
| Back to top |
|
 |
|