Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / September 2004

Tip: Looking for answers? Try searching our database.

Funktion calls in different classes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cnickl - 07 Sep 2004 05:45 GMT
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
Wild Wind - 07 Sep 2004 08:53 GMT
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.