1. 首页
  2. 易语言 - EasyLanguage
  3. Arrays
  4. 二维数组 Two-dimensional Arrays
  1. 首页
  2. 易语言 - EasyLanguage
  3. 二维数组 Two-dimensional Arrays

二维数组 Two-dimensional Arrays

本文通过示例展示如何使用EasyLanguage对象, 特别是与variables对象的.selectedIndex属性和.AsString/.AsDouble等函数的nbarsback参数, 在user.dll中使用二维数组.

This is an example of how to work with 2 dimensional arrays in a user .dll using the EasyLanguageObject, especially related to the .selectedIndex property of the variables object and the nbarsback parameter of the .AsString/.AsDouble, etc. functions.

The following code in C++ was developed to illustrate how this works. Execution of this code results in the following assignments:

TestArray[0, 0] = 1
TestArray[0, 1] = 2
TestArray[1, 0] = 3
TestArray[1, 1] = 4

Here is the C++ function code:

void __stdcall ARRAYTESTFUNC 
( IEasyLanguageObject* pELObj, char* sArrayName ) 
{ 
	IEasyLanguageVariable* pELArray = pELObj->Variables[ sArrayName ] ; 
	pELArray->SelectedIndex[0] = 0 ; 
	pELArray->SelectedIndex[1] = 0 ; 
	pELArray->Value[0] = 1 ; 
	pELArray->SelectedIndex[0] = 0 ; 
	pELArray->SelectedIndex[1] = 1 ; 
	pELArray->Value[0] = 2 ; 
	pELArray->SelectedIndex[0] = 1 ; 
	pELArray->SelectedIndex[1] = 0 ; 
	pELArray->Value[0] = 3 ; 
	pELArray->SelectedIndex[0] = 1 ; 
	pELArray->SelectedIndex[1] = 1 ; 
	pELArray->Value[0] = 4 ; 
} 

Here is the EasyLanguage code that used for testing:

external: "ArrayTest.dll", void, "ARRAYTESTFUNC", IEasyLanguageObject, LPSTR ; 
 
arrays:  TestArray[1, 1]( 0 ) ; 
 
if LastBarOnChart then 
	begin 
	ArrayTestFunc( self, "TestArray" ) ; 
	Print( TestArray[0, 0], " ", TestArray[0, 1], " ", TestArray[1, 0], " ", 
	 TestArray[1, 1] ) ; 
 	end ; 
更新于 2020年5月20日

这篇文章对您有帮助吗?

相关的话题

留言评论