Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Newbie: Passing an object to a class

Newbie: Passing an object to a class

Scheduled Pinned Locked Moved Managed C++/CLI
helpcsharptutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jblau
    wrote on last edited by
    #1

    I am fairly new at programming; I am using Viusal Studio.net 2003. Here is the problem I am trying to solve: I have an MDI parent form which has a control. I also have a child form that needs to tell the control on the parent to do something. I seem to be able to pass the control by reference to the child form class, and if I try to manipulate the control while still in the class constructor, everything works fine. However, when I try to access it elsewhere in the child form, i get an "undeclared identifier" error. Does anyone know how to fix it? Here is some code to show what I am doing: THIS CODE IS IN THE PARENT FORM: private: System::Void button2_Click(System::Object * sender, System::EventArgs * e) { FormChild2 *formChild2 = new FormChild2(myControl); formChild2->MdiParent = this; formChild2->Show(); } THIS CODE IS IN THE FORMCHILD2 FORM: public __gc class FormChild2 : public System::Windows::Forms::Form { public: FormChild2(AxInterop::TWSLib::AxTws *myControl) { InitializeComponent(); myControl->connect("",7496,1); } }; SO while still in the class constructor I can use the "connect" property of the control, which I just passed by reference. However, I want to be able to use that control after a button_click event while in the FormChild2 form. But that is when I get the "undeclared identifier" error. Any suggestions would appreciated. Thanks, Jody Blau

    A 1 Reply Last reply
    0
    • J jblau

      I am fairly new at programming; I am using Viusal Studio.net 2003. Here is the problem I am trying to solve: I have an MDI parent form which has a control. I also have a child form that needs to tell the control on the parent to do something. I seem to be able to pass the control by reference to the child form class, and if I try to manipulate the control while still in the class constructor, everything works fine. However, when I try to access it elsewhere in the child form, i get an "undeclared identifier" error. Does anyone know how to fix it? Here is some code to show what I am doing: THIS CODE IS IN THE PARENT FORM: private: System::Void button2_Click(System::Object * sender, System::EventArgs * e) { FormChild2 *formChild2 = new FormChild2(myControl); formChild2->MdiParent = this; formChild2->Show(); } THIS CODE IS IN THE FORMCHILD2 FORM: public __gc class FormChild2 : public System::Windows::Forms::Form { public: FormChild2(AxInterop::TWSLib::AxTws *myControl) { InitializeComponent(); myControl->connect("",7496,1); } }; SO while still in the class constructor I can use the "connect" property of the control, which I just passed by reference. However, I want to be able to use that control after a button_click event while in the FormChild2 form. But that is when I get the "undeclared identifier" error. Any suggestions would appreciated. Thanks, Jody Blau

      A Offline
      A Offline
      AnsGe
      wrote on last edited by
      #2

      Hai Jody, the myControl in your child form is only the function scope. ie u can only use it in the Constructor because you paased it as an arguement. If you want to use the myControl in ChildForm, please declare a variable of AxTws in ChildForm and link it with Parent from //Parent Form private: System::Void button2_Click(System::Object * sender, System::EventArgs * e) { FormChild2 *formChild2 = new FormChild2(myControl); formChild2->MdiParent = this; fromChild2->myControl=this->myControl; formChild2->Show(); } //Child Form public __gc class FormChild2 : public System::Windows::Forms::Form { public: AxInterop::TWSLib::AxTws *myControl FormChild2() { InitializeComponent(); myControl->connect("",7496,1); } }; Now you can use the myControl from anywhere in the ChildFrom

      J 1 Reply Last reply
      0
      • A AnsGe

        Hai Jody, the myControl in your child form is only the function scope. ie u can only use it in the Constructor because you paased it as an arguement. If you want to use the myControl in ChildForm, please declare a variable of AxTws in ChildForm and link it with Parent from //Parent Form private: System::Void button2_Click(System::Object * sender, System::EventArgs * e) { FormChild2 *formChild2 = new FormChild2(myControl); formChild2->MdiParent = this; fromChild2->myControl=this->myControl; formChild2->Show(); } //Child Form public __gc class FormChild2 : public System::Windows::Forms::Form { public: AxInterop::TWSLib::AxTws *myControl FormChild2() { InitializeComponent(); myControl->connect("",7496,1); } }; Now you can use the myControl from anywhere in the ChildFrom

        J Offline
        J Offline
        jblau
        wrote on last edited by
        #3

        That worked great!! I had no idea I could do it like that. That opens up all sorts of possiblities for me :-D Thank you very much for taking the time to help me out! Jody Blau

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups