Help, please, you need to transfer data from ListBox (right on the screen with 1 student) and memo (With the description of this student) on the first form to the second form in the form of a table and print this table.

Screenshot of the program:

alt text

All data is loaded from text documents.

Details button code:

if (ListBox2->ItemIndex == -1) {exit;} ListBox2->ItemIndex = 0; if (ListBox2->Items->Strings[ListBox2->ItemIndex] == AnsiString("Васин А.В.")) { Memo3->Lines->Clear(); Memo3->Lines->LoadFromFile("texts/vasin.txt"); } if (ListBox2->Items->Strings[ListBox2->ItemIndex] == AnsiString("Иванов С.И")) { Memo3->Lines->Clear(); Memo3->Lines->LoadFromFile("texts/ivanov.txt"); } if (ListBox2->Items->Strings[ListBox2->ItemIndex] == AnsiString("Петров Д.П.")) { Memo3->Lines->Clear(); Memo3->Lines->LoadFromFile("texts/petrov.txt"); } if (ListBox2->Items->Strings[ListBox2->ItemIndex] == AnsiString("Сидоров В.С.")) { Memo3->Lines->Clear(); Memo3->Lines->LoadFromFile("texts/sidorov.txt"); } if (ListBox2->Items->Strings[ListBox2->ItemIndex] == AnsiString("Степанов А.С.")) { Memo3->Lines->Clear(); Memo3->Lines->LoadFromFile("texts/stepanov.txt"); } 
  • And if the number of students = 1000? So will your code grow up? This is something wrong. Think over its optimization. - BuilderC
  • The task is given, it is necessary to solve, nothing was said about the future - streetstorm

1 answer 1

Keep the pointer to the second form in the first, through it will be access to the elements. The pointer must be declared on the base class Form, not Form2

  • A bad answer, or rather not a complete one, should be later brought through static_cast to the required type . Ru.wikipedia.org/wiki/Static_cast - OlegUP