int a,b,c,d,i,f,n,j; int* Mas1 = new int[n]; a = Memo1->Lines->Count; n=0; b=a-1; for (i=0;i<=b;i++) { Mas1[n]=StrToInt(Memo1->Lines->Strings[i]); n=n+1; } Edit2->Text=Mas1[1]; delete (Mas1); 

This code is executed by pressing the button, however, when I press the button twice, an error pops up, it works only once in general. Mistake:

"Invalid Pointer Operation"

And falls out of this line

  Edit2->Text=Mas1[1]; 

Why I do not understand. What is it that twice recorded?

  • And what is n in the second line? Zero? Then normally, Mas [1] does not exist. - alexlz

1 answer 1

Line 2:

 int* Mas1 = new int[n]; //n - не определено. 

In the last line:

 delete (Mas1); //память освобождена неверно. 

It follows:

 delete [] Mas1; 

n, b - extra variables.

 int a = Memo1->Lines->Count; int* Mas1 = new int[a]; for(int i = 0; i < a; i++) Mas1[i]=StrToInt(Memo1->Lines->Strings[i]); Edit2->Text=Mas1[1]; delete [] Mas1; 
  • I don’t understand a bit, because I threw data from the Memo into an array. And if so how best to alter? - Afimida
  • I understand you, thank you. - Afimida