Instance of Windows::Form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Zeile

    #1

    Instance of Windows::Form

    hi there,

    i have the following problem:

    i have 2 normal Windows Forms classes, declared as:

    public __gc class MainForm : public System::Windows ::Forms::Form
    and
    public __gc class FormLayout : public System::Windows ::Forms::Form

    my application starts like this:

    ....
    MainForm *myform;
    myform = new MainForm();
    System::Threadi ng::Thread::Cur rentThread->ApartmentSta te =
    System::Threadi ng::ApartmentSt ate::STA;
    Application::Ru n(myform);
    ....

    somewhere in my MainForm class, i have the following code:
    ....
    FormLayout *formLayout;
    formLayout = new FormLayout();
    formLayout->Show();
    formLayout->InitGL();
    ....etc...

    now my problem: i want to send status messages or change the behavior of
    my MainForm window by pressing a key in my FormLayout form, but i can't
    because i don't know the instance of my MainForm ... because __gc
    objects can't be declared global. so how do i get the instance of my
    form generated by Application::Ru n() ?

    any suggestions ?

    thx a LOT...

    bye
    michael

  • Morten Overgaard

    #2
    Re: Instance of Windows::Form

    try the gcroot<managedC lass*> class template. This makes it possible to
    declare __gc classes global

    /Morten

    "Michael Zeile" <bofh@primusnet z.de> wrote in message
    news:bob5ls$fn7 $03$1@news.t-online.com...[color=blue]
    > hi there,
    >
    > i have the following problem:
    >
    > i have 2 normal Windows Forms classes, declared as:
    >
    > public __gc class MainForm : public System::Windows ::Forms::Form
    > and
    > public __gc class FormLayout : public System::Windows ::Forms::Form
    >
    > my application starts like this:
    >
    > ...
    > MainForm *myform;
    > myform = new MainForm();
    > System::Threadi ng::Thread::Cur rentThread->ApartmentSta te =
    > System::Threadi ng::ApartmentSt ate::STA;
    > Application::Ru n(myform);
    > ...
    >
    > somewhere in my MainForm class, i have the following code:
    > ...
    > FormLayout *formLayout;
    > formLayout = new FormLayout();
    > formLayout->Show();
    > formLayout->InitGL();
    > ...etc...
    >
    > now my problem: i want to send status messages or change the behavior of
    > my MainForm window by pressing a key in my FormLayout form, but i can't
    > because i don't know the instance of my MainForm ... because __gc
    > objects can't be declared global. so how do i get the instance of my
    > form generated by Application::Ru n() ?
    >
    > any suggestions ?
    >
    > thx a LOT...
    >
    > bye
    > michael
    >[/color]


    Comment

    • TGF

      #3
      Re: Instance of Windows::Form

      You could also force the constructor to take a System::Object gc* parameter
      and call the layout form as such...

      FormLayout *formLayout;
      formLayout = new FormLayout(this ); // where 'this' is the MainForm class
      instance


      .....then in the FormLayout class, declare a member as "System::Ob ject gc*
      parentMember". Then you can save the memory address of the parent class in
      your FormLayout constructor....

      FormLayout (System::Object __gc *parent)
      {
      parentMember = parent;
      }

      ....Then whenever you have to call a function in the parent, you can do this
      (Make sure you put the #include "MainForm.h " in the FormLayout.cpp file...

      MainForm *mf = dynamic_cast<Ma inForm *>(parentMember );

      // check for valid ptr to parent before referencing
      if (mf) {

      mf->SomeFunction(s omeParementer);

      }

      Hope this helps.....

      -TGF





      "Michael Zeile" <bofh@primusnet z.de> wrote in message
      news:bob5ls$fn7 $03$1@news.t-online.com...[color=blue]
      > hi there,
      >
      > i have the following problem:
      >
      > i have 2 normal Windows Forms classes, declared as:
      >
      > public __gc class MainForm : public System::Windows ::Forms::Form
      > and
      > public __gc class FormLayout : public System::Windows ::Forms::Form
      >
      > my application starts like this:
      >
      > ...
      > MainForm *myform;
      > myform = new MainForm();
      > System::Threadi ng::Thread::Cur rentThread->ApartmentSta te =
      > System::Threadi ng::ApartmentSt ate::STA;
      > Application::Ru n(myform);
      > ...
      >
      > somewhere in my MainForm class, i have the following code:
      > ...
      > FormLayout *formLayout;
      > formLayout = new FormLayout();
      > formLayout->Show();
      > formLayout->InitGL();
      > ...etc...
      >
      > now my problem: i want to send status messages or change the behavior of
      > my MainForm window by pressing a key in my FormLayout form, but i can't
      > because i don't know the instance of my MainForm ... because __gc
      > objects can't be declared global. so how do i get the instance of my
      > form generated by Application::Ru n() ?
      >
      > any suggestions ?
      >
      > thx a LOT...
      >
      > bye
      > michael
      >[/color]


      Comment

      Working...