I have a coding problem. I hope I can explain it well enough.
I’m using VC++.NET, managed window forms
I want a dialog window change some process going on controlled by a class
defined in my main window form class.
Let my give you some code snippets to make it clearer (hopefully):
public class someclass
{
//code goes here
};
public: __gc class fclDialog
{
public:
void DoSomethingToo(void)
{
fclMainWindow->DoSomethig();
}
};
public __gc class fclMainWindow
{
public:
someclass A = new someclass;
void DoSomething(void)
{
//Code that effects “someclass”
A->…
};
void OpenDialog(void)
{
fclDialog *DlgForm = new fclDialog();
DlgForm->Show();
};
};
I hope you can see what I’m trying to do. A function in the Dialog class has
to call a function in the MainWindow class from which it has been created and
called. When I try to compile my code I get an error saying that I can’t call
a non static function like this, and if I use the keyword static (static void
DoSomething(void)) I get an error saying it can not be used on functions with
file scope. What do I have to change?
Chris
> I have a coding problem. I hope I can explain it well enough.
>
[quoted text clipped - 37 lines]
>
> I hope you can see what I'm trying to do. A function in the Dialog class
has
> to call a function in the MainWindow class from which it has been created and
> called. When I try to compile my code I get an error saying that I can't
call
> a non static function like this, and if I use the keyword static (static void
> DoSomething(void)) I get an error saying it can not be used on functions with
> file scope. What do I have to change?
>
> Chris
Chris,
I'm not sure what you are trying to achieve, but
you might consider passing a pointer to the main window
in the constructor of the dialog so that you can
call the DoSomething method of the instance of
the main window that created the dialog. Something
like
public: __gc class fclDialog
{
private:
fclWindow* m_fcw;
public:
fclDialog(fclWindow* fcw) : m_fcw(fcw) {}
void DoSomethingToo(void)
{
m_fcw->DoSomething();
}
};
public __gc class fclMainWindow
{
public:
...
void OpenDialog(void)
{
fclDialog *DlgForm = new fclDialog(this);
DlgForm->Show();
};
};
HTH,
--
Akin
aknak at aksoto dot idps dot co dot uk