CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Dec 2017
    Posts
    4

    I can not access control of window form from another class in c++

    i have some forms and one class(queue) in my project and i want to take the information of window form(Add.h) from class(queue) but when I include form(Add.h) in class(queue) and create object of form then it show that identifier "Add" is undefined.
    Name:  2017-12-17 (1).jpg
Views: 1573
Size:  25.3 KB

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: I can not access control of window form from another class in c++

    Please, post the code snippets, not a useless screenshot!.
    Please, read carefully the Announcements: Before you post....
    Victor Nijegorodov

  3. #3
    Join Date
    Dec 2017
    Posts
    4

    Re: I can not access control of window form from another class in c++

    Quote Originally Posted by VictorN View Post
    Please, post the code snippets, not a useless screenshot!.
    Please, read carefully the Announcements: Before you post....
    Add.h
    Code:
    #pragma once
    #include <iostream>
    #include "queue.h"
    using std::cout;
    using std::cin;
    using std::endl;
    Add.cpp
    Code:
    #include "Add.h"
    queue.h
    Code:
    #pragma once
    #include <iostream>
    #include "Add.h"
    #include "MMenu.h"
    
    using namespace std;
    
    class NodeType {
    public:
      Add info; //error identifier Add is undefiened
      NodeType *link;
    };
    
    class queue
    {
    public:
       queue();
       void enqueue(Add std); //error identifier Add is undefiened
       void display();
       ~queue();
    };
    
    queue::queue() {}
    
    queue::~queue() {}
    
    void queue::display() {}
    
    void queue::enqueue(Add std) {} //error identifier Add is undefiened
    queue.cpp
    Code:
    #include "queue.h"
    i just started the code and want to get the link between queue class and add form but its show me error "identifier Add is undefined" and if i created another form and include in queue class then also show me error. it seems like when link between class to class is working but class to form is not working.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: I can not access control of window form from another class in c++

    Quote Originally Posted by Sanjay12 View Post
    Add.h
    Code:
    #pragma once
    #include <iostream>
    #include "queue.h"
    using std::cout;
    using std::cin;
    using std::endl;
    Well, your Add.h does not contain any declaration of class (nor struct) Add...
    Victor Nijegorodov

  5. #5
    Join Date
    Dec 2017
    Posts
    4

    Re: I can not access control of window form from another class in c++

    here is full code of Add.h
    Code:
    #pragma once
    #include <iostream>
    #include "queue.h"
    using std::cout;
    using std::cin;
    using std::endl;
    
    
    namespace Assignment {
    
    	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
    	using namespace MySql::Data::MySqlClient;
    
    	/// <summary>
    	/// Summary for Add
    	/// </summary>
    	public ref class Add : public System::Windows::Forms::Form
    	{
    	private: System::Windows::Forms::Form ^ otherform;
    	public:
    		void insert();
    		Add(System::Windows::Forms::Form ^ o)
    		{
    			otherform = o;
    			InitializeComponent();
    			//
    			//TODO: Add the constructor code here
    			//
    		}
    
    	protected:
    		/// <summary>
    		/// Clean up any resources being used.
    		/// </summary>
    		~Add()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
    	private: System::Windows::Forms::Panel^  panel1;
    	private: System::Windows::Forms::Button^  Submit;
    	protected:
    
    	private: System::Windows::Forms::TextBox^  Name;
    
    	private: System::Windows::Forms::Label^  label3;
    	private: System::Windows::Forms::Label^  label2;
    	private: System::Windows::Forms::TextBox^  ID;
    
    	private: System::Windows::Forms::Label^  label1;
    	private: System::Windows::Forms::Button^  button2;
    	private: System::Windows::Forms::Label^  label4;
    	private: System::Windows::Forms::ComboBox^  GenderBox;
    	private: System::Windows::Forms::Label^  label5;
    	private: System::Windows::Forms::ComboBox^  SelPrograme;
    	private: System::Windows::Forms::TextBox^  MNumber;
    	private: System::Windows::Forms::Label^  label7;
    	private: System::Windows::Forms::DateTimePicker^  DOB;
    
    	private: System::Windows::Forms::Label^  label6;
    
    
    	private:
    		/// <summary>
    		/// Required designer variable.
    		/// </summary>
    		System::ComponentModel::Container ^components;
    
    #pragma region Windows Form Designer generated code
    		/// <summary>
    		/// Required method for Designer support - do not modify
    		/// the contents of this method with the code editor.
    		/// </summary>
    		void InitializeComponent(void)
    		{
    			System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Add::typeid));
    			this->panel1 = (gcnew System::Windows::Forms::Panel());
    			this->MNumber = (gcnew System::Windows::Forms::TextBox());
    			this->label7 = (gcnew System::Windows::Forms::Label());
    			this->DOB = (gcnew System::Windows::Forms::DateTimePicker());
    			this->label6 = (gcnew System::Windows::Forms::Label());
    			this->label5 = (gcnew System::Windows::Forms::Label());
    			this->SelPrograme = (gcnew System::Windows::Forms::ComboBox());
    			this->label4 = (gcnew System::Windows::Forms::Label());
    			this->GenderBox = (gcnew System::Windows::Forms::ComboBox());
    			this->Submit = (gcnew System::Windows::Forms::Button());
    			this->Name = (gcnew System::Windows::Forms::TextBox());
    			this->label3 = (gcnew System::Windows::Forms::Label());
    			this->label2 = (gcnew System::Windows::Forms::Label());
    			this->ID = (gcnew System::Windows::Forms::TextBox());
    			this->label1 = (gcnew System::Windows::Forms::Label());
    			this->button2 = (gcnew System::Windows::Forms::Button());
    			this->panel1->SuspendLayout();
    			this->SuspendLayout();
    			// 
    			// panel1
    			// 
    			this->panel1->BackColor = System::Drawing::Color::DarkSlateGray;
    			this->panel1->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
    			this->panel1->Controls->Add(this->MNumber);
    			this->panel1->Controls->Add(this->label7);
    			this->panel1->Controls->Add(this->DOB);
    			this->panel1->Controls->Add(this->label6);
    			this->panel1->Controls->Add(this->label5);
    			this->panel1->Controls->Add(this->SelPrograme);
    			this->panel1->Controls->Add(this->label4);
    			this->panel1->Controls->Add(this->GenderBox);
    			this->panel1->Controls->Add(this->Submit);
    			this->panel1->Controls->Add(this->Name);
    			this->panel1->Controls->Add(this->label3);
    			this->panel1->Controls->Add(this->label2);
    			this->panel1->Controls->Add(this->ID);
    			this->panel1->Controls->Add(this->label1);
    			this->panel1->Location = System::Drawing::Point(179, 52);
    			this->panel1->Name = L"panel1";
    			this->panel1->Size = System::Drawing::Size(382, 331);
    			this->panel1->TabIndex = 1;
    			this->panel1->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Add::panel1_Paint);
    			// 
    			// MNumber
    			// 
    			this->MNumber->Location = System::Drawing::Point(144, 260);
    			this->MNumber->Name = L"MNumber";
    			this->MNumber->Size = System::Drawing::Size(178, 20);
    			this->MNumber->TabIndex = 13;
    			// 
    			// label7
    			// 
    			this->label7->AutoSize = true;
    			this->label7->Font = (gcnew System::Drawing::Font(L"Lucida Handwriting", 9.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
    				static_cast<System::Byte>(0)));
    			this->label7->ForeColor = System::Drawing::Color::FloralWhite;
    			this->label7->Location = System::Drawing::Point(7, 261);
    			this->label7->Name = L"label7";
    			this->label7->Size = System::Drawing::Size(133, 17);
    			this->label7->TabIndex = 12;
    			this->label7->Text = L"Mobile Number";
    			this->label7->TextAlign = System::Drawing::ContentAlignment::TopCenter;
    			// 
    			// DOB
    			// 
    			this->DOB->Location = System::Drawing::Point(144, 220);
    			this->DOB->Name = L"DOB";
    			this->DOB->Size = System::Drawing::Size(178, 20);
    			this->DOB->TabIndex = 11;
    			// 
    			// label6
    			// 
    			this->label6->AutoSize = true;
    			this->label6->Font = (gcnew System::Drawing::Font(L"Lucida Handwriting", 9.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
    				static_cast<System::Byte>(0)));
    			this->label6->ForeColor = System::Drawing::Color::FloralWhite;
    			this->label6->Location = System::Drawing::Point(14, 220);
    			this->label6->Name = L"label6";
    			this->label6->Size = System::Drawing::Size(119, 17);
    			this->label6->TabIndex = 10;
    			this->label6->Text = L"Date Of Birth";
    			this->label6->TextAlign = System::Drawing::ContentAlignment::TopCenter;
    			// 
    			// label5
    			// 
    			this->label5->AutoSize = true;
    			this->label5->Font = (gcnew System::Drawing::Font(L"Lucida Handwriting", 9.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
    				static_cast<System::Byte>(0)));
    			this->label5->ForeColor = System::Drawing::Color::FloralWhite;
    			this->label5->Location = System::Drawing::Point(2, 181);
    			this->label5->Name = L"label5";
    			this->label5->Size = System::Drawing::Size(141, 17);
    			this->label5->TabIndex = 9;
    			this->label5->Text = L"Select Programe";
    			this->label5->TextAlign = System::Drawing::ContentAlignment::TopCenter;
    			// 
    			// SelPrograme
    			// 
    			this->SelPrograme->AutoCompleteCustomSource->AddRange(gcnew cli::array< System::String^  >(3) { L"Male", L"Female", L"Other" });
    			this->SelPrograme->FormattingEnabled = true;
    			this->SelPrograme->Items->AddRange(gcnew cli::array< System::Object^  >(10) {
    				L"BA (Hons) in Accounting and Finance", L"BA (Hons) in Business Management",
    					L"BA (Hons) in Marketing Management", L"BA (Hons) in Media Marketing", L"BA (Hons) in Computer Science", L"BA (Hons) in Computer Game Development",
    					L"BA (Hons) in Information Technology", L"BA (Hons) in Software Engineering", L"BA (Hons) in Electrical and Electronic Engineering",
    					L"BA (Hons) in Mechatronic Engineering"
    			});
    			this->SelPrograme->Location = System::Drawing::Point(144, 179);
    			this->SelPrograme->Name = L"SelPrograme";
    			this->SelPrograme->Size = System::Drawing::Size(178, 21);
    			this->SelPrograme->TabIndex = 8;
    			// 
    			// label4
    			// 
    			this->label4->AutoSize = true;
    			this->label4->Font = (gcnew System::Drawing::Font(L"Lucida Handwriting", 9.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
    				static_cast<System::Byte>(0)));
    			this->label4->ForeColor = System::Drawing::Color::FloralWhite;
    			this->label4->Location = System::Drawing::Point(3, 138);
    			this->label4->Name = L"label4";
    			this->label4->Size = System::Drawing::Size(135, 17);
    			this->label4->TabIndex = 7;
    			this->label4->Text = L"Student Gender";
    			this->label4->TextAlign = System::Drawing::ContentAlignment::TopCenter;
    			// 
    			// GenderBox
    			// 
    			this->GenderBox->AutoCompleteCustomSource->AddRange(gcnew cli::array< System::String^  >(3) { L"Male", L"Female", L"Other" });
    			this->GenderBox->FormattingEnabled = true;
    			this->GenderBox->Items->AddRange(gcnew cli::array< System::Object^  >(3) { L"Male", L"Female", L"Other" });
    			this->GenderBox->Location = System::Drawing::Point(144, 136);
    			this->GenderBox->Name = L"GenderBox";
    			this->GenderBox->Size = System::Drawing::Size(178, 21);
    			this->GenderBox->TabIndex = 6;
    			// 
    			// Submit
    			// 
    			this->Submit->BackColor = System::Drawing::Color::Gainsboro;
    			this->Submit->Font = (gcnew System::Drawing::Font(L"Franklin Gothic Book", 11.25F, static_cast<System::Drawing::FontStyle>((System::Drawing::FontStyle::Bold | System::Drawing::FontStyle::Italic)),
    				System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(0)));
    			this->Submit->ForeColor = System::Drawing::SystemColors::Desktop;
    			this->Submit->Location = System::Drawing::Point(181, 292);
    			this->Submit->Name = L"Submit";
    			this->Submit->Size = System::Drawing::Size(99, 30);
    			this->Submit->TabIndex = 5;
    			this->Submit->Text = L"Submit";
    			this->Submit->UseVisualStyleBackColor = false;
    			this->Submit->Click += gcnew System::EventHandler(this, &Add::Submit_Click);
    			// 
    			// Name
    			// 
    			this->Name->Location = System::Drawing::Point(144, 93);
    			this->Name->Name = L"Name";
    			this->Name->Size = System::Drawing::Size(178, 20);
    			this->Name->TabIndex = 4;
    			// 
    			// label3
    			// 
    			this->label3->AutoSize = true;
    			this->label3->Font = (gcnew System::Drawing::Font(L"Lucida Handwriting", 9.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
    				static_cast<System::Byte>(0)));
    			this->label3->ForeColor = System::Drawing::Color::FloralWhite;
    			this->label3->Location = System::Drawing::Point(3, 93);
    			this->label3->Name = L"label3";
    			this->label3->Size = System::Drawing::Size(124, 17);
    			this->label3->TabIndex = 3;
    			this->label3->Text = L"Student Name";
    			this->label3->TextAlign = System::Drawing::ContentAlignment::TopCenter;
    			// 
    			// label2
    			// 
    			this->label2->AutoSize = true;
    			this->label2->Font = (gcnew System::Drawing::Font(L"Lucida Handwriting", 9.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
    				static_cast<System::Byte>(0)));
    			this->label2->ForeColor = System::Drawing::Color::FloralWhite;
    			this->label2->Location = System::Drawing::Point(14, 47);
    			this->label2->Name = L"label2";
    			this->label2->Size = System::Drawing::Size(119, 17);
    			this->label2->TabIndex = 1;
    			this->label2->Text = L"Unique Name";
    			this->label2->TextAlign = System::Drawing::ContentAlignment::TopCenter;
    			// 
    			// ID
    			// 
    			this->ID->Location = System::Drawing::Point(144, 47);
    			this->ID->Name = L"ID";
    			this->ID->Size = System::Drawing::Size(178, 20);
    			this->ID->TabIndex = 2;
    			this->ID->TextChanged += gcnew System::EventHandler(this, &Add::ID_TextChanged);
    			// 
    			// label1
    			// 
    			this->label1->AutoSize = true;
    			this->label1->Font = (gcnew System::Drawing::Font(L"Lucida Handwriting", 14.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
    				static_cast<System::Byte>(0)));
    			this->label1->ForeColor = System::Drawing::Color::FloralWhite;
    			this->label1->Location = System::Drawing::Point(56, 0);
    			this->label1->Name = L"label1";
    			this->label1->Size = System::Drawing::Size(251, 24);
    			this->label1->TabIndex = 0;
    			this->label1->Text = L"Add Students Record";
    			this->label1->TextAlign = System::Drawing::ContentAlignment::TopCenter;
    			// 
    			// button2
    			// 
    			this->button2->BackColor = System::Drawing::Color::Gainsboro;
    			this->button2->Font = (gcnew System::Drawing::Font(L"Franklin Gothic Book", 11.25F, static_cast<System::Drawing::FontStyle>((System::Drawing::FontStyle::Bold | System::Drawing::FontStyle::Italic)),
    				System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(0)));
    			this->button2->ForeColor = System::Drawing::SystemColors::Desktop;
    			this->button2->Location = System::Drawing::Point(-1, -1);
    			this->button2->Name = L"button2";
    			this->button2->Size = System::Drawing::Size(86, 30);
    			this->button2->TabIndex = 6;
    			this->button2->Text = L"Go Back";
    			this->button2->UseVisualStyleBackColor = false;
    			this->button2->Click += gcnew System::EventHandler(this, &Add::button2_Click);
    			// 
    			// Add
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->BackgroundImage = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"$this.BackgroundImage")));
    			this->ClientSize = System::Drawing::Size(720, 382);
    			this->Controls->Add(this->button2);
    			this->Controls->Add(this->panel1);
    			this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::SizableToolWindow;
    			this->Name = L"Add";
    			this->Text = L"Add Student Record";
    			this->Load += gcnew System::EventHandler(this, &Add::Add_Load);
    			this->panel1->ResumeLayout(false);
    			this->panel1->PerformLayout();
    			this->ResumeLayout(false);
    
    		}
    #pragma endregion
    	private: System::Void panel1_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) {
    	}
    private: System::Void ID_TextChanged(System::Object^  sender, System::EventArgs^  e) {
    }
    private: System::Void Add_Load(System::Object^  sender, System::EventArgs^  e) {
    }
    private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
    	this->Hide();
    	otherform->Show();
    }
    
    		 
    void Add::insert() {
    	String ^ UnName = ID->Text;
    	String ^studentName = Name->Text;
    	String ^ studentGender = GenderBox->Text;
    	String ^ studentProg = SelPrograme->Text;
    	String ^ studentDOB = DOB->Text;
    	String ^ studentMOB = MNumber->Text;
    
    }
    
    
    private: System::Void Submit_Click(System::Object^  sender, System::EventArgs^  e) {
    }	
    };
    }

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: I can not access control of window form from another class in c++

    Quote Originally Posted by Sanjay12 View Post
    here is full code of Add.h
    Code:
    #pragma once
    #include <iostream>
    #include "queue.h"
    using std::cout;
    using std::cin;
    using std::endl;
    
    
    namespace Assignment {
    
    	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
    	using namespace MySql::Data::MySqlClient;
    ....
    }
    This is the managed code.
    But what you showed in your post#3 looks like the native C++ one!
    Why do you want to mix them?
    Victor Nijegorodov

  7. #7
    Join Date
    Dec 2017
    Posts
    4

    Re: I can not access control of window form from another class in c++

    sorry sir. My code may confuse you. but i am just trying to get the textbox value of Add.h form and use it in queue.cpp class, but it shows me error like identifier Add is undefined. i just want to know how can i get the object of Add.h class and can use its methods and function in queue.cpp class.
    i also try forward declaration but still it is showing that "incomplete type is not allowed.
    i have try many way but still can't get any solution.
    thanks for replying me

  8. #8
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: I can not access control of window form from another class in c++

    but add is c++/cli and queue is c++. c++/cli is not the same as c++. As this seems to be a c+/cli issue, I've moved this thread to the c++/cli forum.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  9. #9
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: I can not access control of window form from another class in c++

    Ignoring the native C++ vs. C++/CLI issue for now, as well as some other problems with your code I anticipate to arise in the near future, for the sake of simplicity...

    Because it is defined in the namespace Assignment, your class Add is not in scope in queue.h, that's why you get these errors. Add a using namespace Assignment; directive to your code before you use Add, or qualify it by writing Assignment::Add rather than just Add instead.

    Also, as Add is a ref class, you need to declare a parameter to pass an instance of it as a tracking handle by writing Add ^std (or Assignment::Add ^std) instead of Add std.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured