RAD Studio VCL Reference
|
Specifies whether the strings in the list should be automatically sorted.
property Sorted: Boolean;
__property Boolean Sorted;
Set Sorted to true to cause the strings in the list to be automatically sorted in ascending order. Set Sorted to false to allow strings to remain where they are inserted. When Sorted is false, the strings in the list can be put in ascending order at any time by calling the Sort method.
When Sorted is true, do not use Insert to add strings to the list. Instead, use Add, which will insert the new strings in the appropriate position. When Sorted is false, use Insert to add strings to an arbitrary position in the list, or Add to add strings to the end of the list.
C++ Examples:
/* 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: */ #include <memory> //for STL auto_ptr class void __fastcall TForm1::FormCreate(TObject *Sender) { std::auto_ptr<TStringList> list(new TStringList()); list->Add("Plants"); list->Add("Animals"); list->Add("Minerals"); list->Sorted = true; ListBox1->Items->AddStrings(list.get()); }
Delphi Examples:
{ 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: } procedure TForm1.FormCreate(Sender: TObject); var MyList: TStringList; begin MyList := TStringList.Create; MyList.Add('Plants'); MyList.Add('Animals'); MyList.Add('Minerals'); MyList.Sorted := True; ListBox1.Items.AddStrings(MyList); MyList.Free; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|