Domyślam się, że tak, bo nie zrozumiałeś i napisałeś to co ja już stosowałem wcześniej. Odwołałeś się z klasy głównej do textBoxa klasy B, natomiast do tej dodaj jeszcze odwołanie z klasy B do klasy głównej. I wtedy będzie dobrze. Tak jak pisałem, problem jest gdy dodam include klasy głównej wewnątrz podrzędnej.
Może szybko napiszę przykład który pokaże problem, skompiluję go i wkleję. zw ;p
To jest forma główna, zawiera tylko buttona:
#pragma once
#include "class.h"
#include "aaa.h" // <-- Tu tkwi problem, gdy chcę dodać podrzędną klasę do głównej oraz //gdy główna musi być użyta w podrzędnej.
namespace aa {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
protected:
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)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(197, 12);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 0;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 262);
this->Controls->Add(this->button1);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
}
#pragma endregion
public:
data KKK;
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
KKK.NAME[1] = "sss";
this->Close();
}
};
}
To jest klasa, w której jest zdefiniowany typ danych data:
#pragma once
namespace aa
{
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public ref class data
{
public:
array<String ^> ^ NAME;
data()
{
NAME = gcnew array<String ^>(100);
}
};
}
A to jest ostatnia klasa:
#pragma once
#include "Form1.h"
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
namespace aa {
/// <summary>
/// Summary for aaa
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public ref class aaa : public System::Windows::Forms::Form
{
public:
aaa(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~aaa()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::TextBox^ textBox1;
protected:
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)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(198, 47);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 0;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &aaa::button1_Click);
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(177, 114);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(100, 20);
this->textBox1->TabIndex = 1;
//
// aaa
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 262);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->button1);
this->Name = L"aaa";
this->Text = L"aaa";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
Form1^ dlg = gcnew Form1();
dlg->KKK.NAME[1] = "as";
}
};
}
I lista błędów wynikająca z użycia czegoś czego (teoretycznie) nie ma:
1>------ Rebuild All started: Project: aa, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'aa', configuration 'Debug|Win32'
1>Compiling...
1>stdafx.cpp
1>Compiling...
1>aaa.cpp
1>AssemblyInfo.cpp
1>aa.cpp
1>c:\users\slynx\documents\visual studio 2008\projects\aa\aa\aaa.h(99) : error C2065: 'Form1' : undeclared identifier
1>c:\users\slynx\documents\visual studio 2008\projects\aa\aa\aaa.h(99) : error C2065: 'dlg' : undeclared identifier
1>c:\users\slynx\documents\visual studio 2008\projects\aa\aa\aaa.h(99) : error C2061: syntax error : identifier 'Form1'
1>c:\users\slynx\documents\visual studio 2008\projects\aa\aa\aaa.h(100) : error C2065: 'dlg' : undeclared identifier
1>c:\users\slynx\documents\visual studio 2008\projects\aa\aa\aaa.h(100) : error C2227: left of '->KKK' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:\users\slynx\documents\visual studio 2008\projects\aa\aa\aaa.h(100) : error C2228: left of '.NAME' must have class/struct/union
1>Generating Code...
1>Build log was saved at "file://c:\Users\Slynx\Documents\Visual Studio 2008\Projects\aa\aa\Debug\BuildLog.htm"
1>aa - 6 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
Nie wiem, może coś źle robię, może nie powinno się nawzajem includować plików, ale po prostu nie wiem jak stworzyć taką zależność :/
Damn, myślałem, że większy kod jest przewijany w okienku, a nie wszystko rozłożone na oknie ;p Ale już trudno.