TStringListSorted (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example uses a list box on a form. When the application runs, a string list object is created and three strings are added to it. The strings are sorted and added to the list box, where they appear in their sorted order.


Code

#include <memory>       //For STL auto_ptr class

__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
  std::auto_ptr<TStringList> list(new TStringList());
  list->Add("Plants");
  list->Add("Animals");
  list->Add("Minerals");
  list->Sorted = true;
  ListBox1->Items->AddStrings(list.get());
}

Uses