From f20f3aa1efae8ff9dfeedd38defec423d0a20032 Mon Sep 17 00:00:00 2001 From: paul Date: Thu, 26 Aug 2010 16:39:45 +0000 Subject: [PATCH] lcl: add public property TCustomListView.ColumnCount, win32: don't access listview columns array out of it bounds (issue #0017263) git-svn-id: trunk@27199 - --- lcl/comctrls.pp | 2 ++ lcl/include/customlistview.inc | 5 +++++ lcl/interfaces/win32/win32wscustomlistview.inc | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lcl/comctrls.pp b/lcl/comctrls.pp index 1ff7ea286d..5bfc90f5df 100644 --- a/lcl/comctrls.pp +++ b/lcl/comctrls.pp @@ -1041,6 +1041,7 @@ type FOnAdvancedCustomDrawSubItem: TLVAdvancedCustomDrawSubItemEvent; FProperties: TListViewProperties; function GetBoundingRect: TRect; + function GetColumnCount: Integer; function GetColumnFromIndex(AIndex: Integer): TListColumn; function GetDropTarget: TListItem; function GetFocused: TListItem; @@ -1155,6 +1156,7 @@ type property Canvas: TCanvas read FCanvas; property Checkboxes: Boolean index Ord(lvpCheckboxes) read GetProperty write SetProperty default False; property Column[AIndex: Integer]: TListColumn read GetColumnFromIndex; + property ColumnCount: Integer read GetColumnCount; property DropTarget: TListItem read GetDropTarget write SetDropTarget; property FlatScrollBars: Boolean index Ord(lvpFlatScrollBars) read GetProperty write SetProperty default False; property FullDrag: Boolean index Ord(lvpFullDrag) read GetProperty write SetProperty default False; diff --git a/lcl/include/customlistview.inc b/lcl/include/customlistview.inc index abafc39284..058ee75e84 100644 --- a/lcl/include/customlistview.inc +++ b/lcl/include/customlistview.inc @@ -725,6 +725,11 @@ begin else Result := TWSCustomListViewClass(WidgetSetClass).GetBoundingRect(Self); end; +function TCustomListView.GetColumnCount: Integer; +begin + Result := FColumns.Count; +end; + function TCustomListView.GetColumnFromIndex(AIndex: Integer): TListColumn; begin Result := FColumns[AIndex]; diff --git a/lcl/interfaces/win32/win32wscustomlistview.inc b/lcl/interfaces/win32/win32wscustomlistview.inc index f1c63448da..5cfaf3afe4 100644 --- a/lcl/interfaces/win32/win32wscustomlistview.inc +++ b/lcl/interfaces/win32/win32wscustomlistview.inc @@ -678,7 +678,7 @@ begin // We will therefore postpone all autosizing until EndUpdate where we do // it only once per column. - if ALV.Column[ASubIndex].AutoSize and (TCustomListViewAccess(ALV).GetUpdateCount = 0) then + if (ASubIndex >= 0) and (ASubIndex < ALV.ColumnCount) and ALV.Column[ASubIndex].AutoSize and (TCustomListViewAccess(ALV).GetUpdateCount = 0) then ListView_SetColumnWidth(ALV.Handle, ASubIndex, AutoSizeWidth); end;