funkcja statyczna a zmiana atrybutów kontrolek w VS C++

0

Mam taki sobie kod i chciałbym z wnętrza statycznej funkcji

int lua_func(lua_State *L)

zmienić atrybut Text textboxa textbox1. Da się to jakoś zrobić?

#pragma once

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;
	using namespace System::Collections::Generic;
	using namespace System::Threading;
	using namespace std;

	int lua_func(lua_State *L){
		
		//this->textbox1->Text = "example";

		lua_pushboolean(L, true);
		return 1;
	}

	/// <summary>
	/// Summary for Form1
	/// </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:
		/// <summary>
		/// Required designer variable.
		/// </summary>


#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)
		{
			(...)
		}
#pragma endregion

	(...)

};
}

0

Sprawdź i napisz. Jeśli się nie da to daj komunikat błędu.

0
int lua_debug(lua_State *L){
		this->DEBUG->Text += "hai\r\n";
		lua_pushboolean(L, true);
		return 1;
}
	}

Błąd:

 error C2355: 'this' : can only be referenced inside non-static member functions
0

A czymże miałby być this wewnątrz statycznej metody? o_O

0

Wiem że tak jak ja próbuję się nie da, dlatego pytam tutaj - jak inaczej można to zrobić?

0

A czemu nie mozesz przekazać do tej funkcji referencji do obiektu który chcesz zmienić? Przecież tak się to właśnie robi...

0

Próbuję przekazać funkcji uchwyt do kontrolki w Dictionary:

	Dictionary<String^, Control^>^ Dcontrols;

	int lua_getControlEnabled(lua_State *L){
		// boolean getControlEnabled(name)
		int parameters = lua_gettop(L);
		if (parameters != 1)
		{
			lua_pushboolean(L, false);
			return 1;
		}

		string control_name = lua_tostring(L, 1);
		Control^ control = Dcontrols[control_name];

		if (control->Enabled == true)
		{
			lua_pushboolean(L, true);
			return 1;
		}
		else
		{
			lua_pushboolean(L, false);
			return 1;
		}
	}

Ale,

error C3145: 'Dcontrols' : global or static variable may not have managed type 'System::Collections::Generic::Dictionary<TKey,TValue> ^'
1>          with
1>          [
1>              TKey=System::String ^,
1>              TValue=System::Windows::Forms::Control ^
1>          ]
1>          may not declare a global or static variable, or a member of a native type that refers to objects in the gc heap
1>d:\prog\c++\bot\bot\Form1.h(22): error C3145: 'Dcontrols_triggers' : global or static variable may not have managed type 'System::Collections::Generic::Dictionary<TKey,TValue> ^'
1>          with
1>          [
1>              TKey=System::Windows::Forms::Control ^,
1>              TValue=System::String ^
1>          ]
1>          may not declare a global or static variable, or a member of a native type that refers to objects in the gc heap

1 użytkowników online, w tym zalogowanych: 0, gości: 1