TStringListAdd (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example uses a list box and a label on a form. When the application runs, a string list object is created and three strings are added to it. The Find method searches the strings to look for a match with the string ‘Flowers’. If the string is found, all the strings in the string list are added to the list box, and the index value of the ‘Flowers’ string appears in the caption of the label control.


Code

#include <memory>       //For STL auto_ptr class

__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
  int Index;
  std::auto_ptr<TStringList> MyList(new TStringList());
  MyList->Add(L"Animalsૐ૧૪");
  MyList->Add(L"Flowersૐ૧૪");
  MyList->Add(L"Oceanૐ૧૪");
  MyList->Sort(); // Find only works on sorted lists.
  if (MyList->Find(L"Flowersૐ૧૪", Index))
  {
	ListBox1->Items->AddStrings(MyList.get());
	Label1->Caption = L"Flowersૐ૧૪ has an index value of " + String(Index);
  }
}

Uses