Start a new topic

Multiple class instances

 The next code doesn't compile


NexText t0 = NexText(0, 1, "t0");
NexText t1 = NexText(0, 1, "t1");

NexText* pointer[]={
  &t0,
  &t1
};

pointer[0]->setText("123");


 The output of the complier shows:


\CompText.ino.cpp.o"
CompText:36: error: 'pointer' does not name a type

 pointer[0]->setText("123");

 ^
exit status 1
'pointer' does not name a type


Any Idea?




I just tried this little program and compiles fine:

 

#include "Nextion.h"
NexText t0 = NexText(0, 1, "t0");
NexText t1 = NexText(0, 1, "t1");

NexText* pointer[]={
  &t0,
  &t1
};
void setup(){
	pointer[0]->setText("1234");
}
void loop(){

}

 However, I noticed that your Cid's are identical which would probably lead to a bug during execution. both have the value of "1". In my code I have stopped filling in the text value and replaced it with NULL. It only wastes RAM storage while it is not used.


So I would change it to:

 

#include "Nextion.h"
NexText t0 = NexText(0, 1, NULL);
NexText t1 = NexText(0, 2, NULL);

NexText* pointer[]={
  &t0,
  &t1
};
void setup(){
	pointer[0]->setText("1234");
}
void loop(){

}

 


1 person likes this
Ok let me try thanks for you support

 

Login or Signup to post a comment