码迷,mamicode.com
首页 > 其他好文 > 详细

TStringList 的Sorted属性

时间:2014-12-01 15:34:21      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:style   blog   ar   color   sp   数据   div   log   bs   

1 、设置 sorted := true;

2、添加数据

add(‘3‘);add(‘4‘);add(‘1‘);

showmessage(commatext);// 1,3,4

3、再修改Sorted属性 为 false ,前面已经添加的数据 不会恢复为添加时的顺序341

添加新数据 add(‘5‘);

4、showmessage(commatext);//1345

procedure TStringList.SetSorted(Value: Boolean);

begin
if FSorted <> Value then
begin
if Value then Sort;  //修改sorted属性时,只有 新值是 true时 才会排序;新值是 false时,不会排序
FSorted := Value;
end;
end;
procedure TStringList.Sort;
begin
  CustomSort(StringListCompareStrings);
end;

procedure TStringList.CustomSort(Compare: TStringListSortCompare);
begin
  if not Sorted and (FCount > 1) then//sorted是false时 才会排序
  begin
    Changing;
    QuickSort(0, FCount - 1, Compare);
    Changed;
  end;
end;

 

TStringList 的Sorted属性

标签:style   blog   ar   color   sp   数据   div   log   bs   

原文地址:http://www.cnblogs.com/CodeGear/p/4135065.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!