BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Accessing Main methods in Child Window

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics)
View previous topic :: View next topic  
Author Message
MAC
Guest





PostPosted: Wed Feb 28, 2007 11:43 pm    Post subject: Accessing Main methods in Child Window Reply with quote



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





PostPosted: Thu Mar 01, 2007 3:31 am    Post subject: Re: Accessing Main methods in Child Window Reply with quote



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





PostPosted: Thu Mar 01, 2007 3:35 am    Post subject: Re: Accessing Main methods in Child Window Reply with quote



"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





PostPosted: Thu Mar 01, 2007 3:37 am    Post subject: Re: Accessing Main methods in Child Window Reply with quote

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





PostPosted: Thu Mar 01, 2007 3:43 am    Post subject: Re: Accessing Main methods in Child Window Reply with quote

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





PostPosted: Thu Mar 01, 2007 4:09 am    Post subject: Re: Accessing Main methods in Child Window Reply with quote

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





PostPosted: Thu Mar 01, 2007 5:23 am    Post subject: Re: Accessing Main methods in Child Window Reply with quote

"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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.