LCL: Set TCustomListView.SortColumn default to -1, improve range checks

git-svn-id: trunk@38287 -
This commit is contained in:
juha 2012-08-20 17:58:56 +00:00
parent c4d537e314
commit b3b28cb94d
2 changed files with 7 additions and 3 deletions

View File

@ -1421,7 +1421,7 @@ type
property ShowWorkAreas: Boolean index Ord(lvpShowWorkAreas) read GetProperty write SetProperty default False;
property SmallImages: TCustomImageList index Ord(lvilSmall) read GetImageList write SetImageList;
property SortType: TSortType read FSortType write SetSortType default stNone;
property SortColumn: Integer read FSortColumn write SetSortColumn default 0;
property SortColumn: Integer read FSortColumn write SetSortColumn default -1;
property SortDirection: TSortDirection read FSortDirection write SetSortDirection default sdAscending;
property StateImages: TCustomImageList index Ord(lvilState) read GetImageList write SetImageList;
property ToolTips: Boolean index Ord(lvpToolTips) read GetProperty write SetProperty default True;

View File

@ -127,6 +127,7 @@ begin
FCompStyle := csListView;
FViewStyle := vsList;
FSortType := stNone;
FSortColumn := -1;
for lvil := Low(TListViewImageList) to High(TListViewImageList) do
begin
@ -229,8 +230,10 @@ begin
begin
if SortType <> stNone then
begin
if AColumn.Index <> SortColumn then
SortColumn := AColumn.Index
if AColumn.Index <> SortColumn then begin
SortColumn := AColumn.Index;
SortDirection := sdAscending;
end
else
begin
// with same column we are changing only direction
@ -874,6 +877,7 @@ var
AItemIndex: Integer;
begin
if FSortType = stNone then exit;
if (FSortColumn < 0) or (FSortColumn >= ColumnCount) then exit;
if FListItems.Count < 2 then exit;
if lffPreparingSorting in FFlags then exit;