Witam wszystkich, uczę się C++\CLI (Windows Form) i trafiłem na dziwny problem.
Przy próbie dostępu do "obiektu Formy" z zewnętrznej funkcji wyskakuje mi error 'Form1' : undeclared identifier ?? .
Oto kod programu:
#pragma once
void Aktualizuj()
{
Form1^ forma = gcnew Form1;
forma->progressBar1->Value = 100;
}
namespace Program {
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
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
// koniec
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
protected:
public: System::Windows::Forms::ProgressBar^ progressBar1;
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->progressBar1 = (gcnew System::Windows::Forms::ProgressBar());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(177, 205);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(217, 30);
this->button1->TabIndex = 0;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// progressBar1
//
this->progressBar1->Location = System::Drawing::Point(52, 81);
this->progressBar1->Name = L"progressBar1";
this->progressBar1->Size = System::Drawing::Size(476, 35);
this->progressBar1->TabIndex = 1;
this->progressBar1->Value = 1;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(560, 291);
this->Controls->Add(this->progressBar1);
this->Controls->Add(this->button1);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
Aktualizuj(); // powinien zaktualizowac się progressbar
}
};
}
error:
1>c:\users\datex\documents\visual studio 2010\projects\downlodertest\downlodertest\Form1.h(5): error C2065: 'Form1' : undeclared identifier
1>c:\users\datex\documents\visual studio 2010\projects\downlodertest\downlodertest\Form1.h(5): error C2065: 'forma' : undeclared identifier
1>c:\users\datex\documents\visual studio 2010\projects\downlodertest\downlodertest\Form1.h(5): error C2061: syntax error : identifier 'Form1'
1>c:\users\datex\documents\visual studio 2010\projects\downlodertest\downlodertest\Form1.h(6): error C2065: 'forma' : undeclared identifier
1>c:\users\datex\documents\visual studio 2010\projects\downlodertest\downlodertest\Form1.h(6): error C2227: left of '->progressBar1' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:\users\datex\documents\visual studio 2010\projects\downlodertest\downlodertest\Form1.h(6): error C2227: left of '->Value' must point to class/struct/union/generic type
W czym tkwi problem?