Here I am creating the elements:
ListBox1->Items->Add(ned1->Text); I give them handlers
for(int i(0);i<ListBox1->Count;i++) { ListBox1->ItemByIndex(i)->OnClick = ListBoxItem1Click; } And also created a handler.
void __fastcall TTabbedForm::TabItemClick(TObject *Sender) { ListBox2->Items->SaveToFile("/sdcard/"+(ListBox1->Items->Strings[ListBox1->ItemIndex])+".txt"); } The program works like this: when you first click on any of the created elements (TListBox), an error (photo) crashes. 
All other clicks on the same or any other elements occur what is in the handler (i.e., it works properly). what is the problem. It seems to me that I use the index of the selected item in its own processor. If so, how to make it work?


void __fastcall TForm1::ListBox1Click(TObject *Sender) { Edit1->Text = ListBox1->Items->Strings[ListBox1->ItemIndex]; }void __fastcall TForm1::ListBox1Click(TObject *Sender) { Edit1->Text = ListBox1->Items->Strings[ListBox1->ItemIndex]; }- KoVadim