Changeset 463 for branches/highdpi/Packages/Common/ListViewSort.pas
- Timestamp:
- Nov 29, 2023, 2:35:44 PM (12 months ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/highdpi/Packages/Common/ListViewSort.pas
r462 r463 1 unit UListViewSort;1 unit ListViewSort; 2 2 3 3 // Date: 2019-05-17 4 5 {$mode delphi}6 4 7 5 interface … … 9 7 uses 10 8 UDpiControls, {$IFDEF Windows}Windows, CommCtrl, LMessages, {$ENDIF}Classes, Graphics, ComCtrls, SysUtils, 11 Controls, DateUtils, Dialogs, fgl,Forms, Grids, StdCtrls, ExtCtrls,12 LclIntf, LclType, LResources ;9 Controls, DateUtils, Dialogs, Forms, Grids, StdCtrls, ExtCtrls, 10 LclIntf, LclType, LResources, Generics.Collections, Generics.Defaults; 13 11 14 12 type … … 19 17 TCompareEvent = function (Item1, Item2: TObject): Integer of object; 20 18 TListFilterEvent = procedure (ListViewSort: TListViewSort) of object; 19 20 TObjects = TObjectList<TObject>; 21 21 22 22 { TListViewSort } … … 27 27 FOnCompareItem: TCompareEvent; 28 28 FOnFilter: TListFilterEvent; 29 FOnCustomDraw: T LVCustomDrawItemEvent;29 FOnCustomDraw: TDpiLVCustomDrawItemEvent; 30 30 {$IFDEF Windows}FHeaderHandle: HWND;{$ENDIF} 31 31 FColumn: Integer; … … 42 42 procedure GetCheckBias(var XBias, YBias, BiasTop, BiasLeft: Integer; 43 43 const ListView: TDpiListView); 44 procedure ListViewCustomDrawItem(Sender: T CustomListView;44 procedure ListViewCustomDrawItem(Sender: TDpiCustomListView; 45 45 Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean); 46 46 procedure ListViewClick(Sender: TObject); … … 52 52 {$ENDIF} 53 53 public 54 List: TFPGObjectList<TObject>;55 Source: TFPGObjectList<TObject>;54 Source: TObjects; 55 List: TObjects; 56 56 constructor Create(AOwner: TComponent); override; 57 57 destructor Destroy; override; … … 67 67 property OnFilter: TListFilterEvent read FOnFilter 68 68 write FOnFilter; 69 property OnCustomDraw: T LVCustomDrawItemEvent read FOnCustomDraw69 property OnCustomDraw: TDpiLVCustomDrawItemEvent read FOnCustomDraw 70 70 write FOnCustomDraw; 71 71 property OnColumnWidthChanged: TNotifyEvent read FOnColumnWidthChanged … … 81 81 FOnChange: TNotifyEvent; 82 82 FStringGrid1: TDpiStringGrid; 83 procedure DoOnChange; 83 84 procedure GridDoOnKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); 84 85 procedure GridDoOnResize(Sender: TObject); … … 90 91 function TextEnteredColumn(Index: Integer): Boolean; 91 92 function GetColValue(Index: Integer): string; 93 procedure Reset; 92 94 property StringGrid: TDpiStringGrid read FStringGrid1 write FStringGrid1; 93 95 published … … 147 149 destructor TListViewEx.Destroy; 148 150 begin 149 inherited Destroy;151 inherited; 150 152 end; 151 153 152 154 { TListViewFilter } 155 156 procedure TListViewFilter.DoOnChange; 157 begin 158 if Assigned(FOnChange) then FOnChange(Self); 159 end; 153 160 154 161 procedure TListViewFilter.GridDoOnKeyUp(Sender: TObject; var Key: Word; 155 162 Shift: TShiftState); 156 163 begin 157 if Assigned(FOnChange) then 158 FOnChange(Self); 164 DoOnChange; 159 165 end; 160 166 … … 229 235 end; 230 236 237 procedure TListViewFilter.Reset; 238 var 239 I: Integer; 240 begin 241 with StringGrid do 242 for I := 0 to ColCount - 1 do 243 Cells[I, 0] := ''; 244 DoOnChange; 245 end; 246 231 247 { TListViewSort } 232 248 … … 322 338 ListViewSortCompare: TCompareEvent; 323 339 324 function ListViewCompare(const Item1, Item2: TObject): Integer;340 function ListViewCompare(constref Item1, Item2: TObject): Integer; 325 341 begin 326 342 Result := ListViewSortCompare(Item1, Item2); … … 333 349 ListViewSortCompare := Compare; 334 350 if (List.Count > 0) then 335 List.Sort( ListViewCompare);351 List.Sort(TComparer<TObject>.Construct(ListViewCompare)); 336 352 end; 337 353 … … 339 355 begin 340 356 if Assigned(FOnFilter) then FOnFilter(Self) 341 else if Assigned(Source) then 342 List.Assign(Source) else 357 else if Assigned(Source) then begin 343 358 List.Clear; 359 List.AddRange(Source); 360 end else List.Clear; 344 361 if ListView.Items.Count <> List.Count then 345 362 ListView.Items.Count := List.Count; … … 396 413 begin 397 414 inherited; 398 List := T FPGObjectList<TObject>.Create;399 List. FreeObjects := False;415 List := TObjects.Create; 416 List.OwnsObjects := False; 400 417 end; 401 418 402 419 destructor TListViewSort.Destroy; 403 420 begin 404 List.Free;421 FreeAndNil(List); 405 422 inherited; 406 423 end; … … 491 508 end; 492 509 493 procedure TListViewSort.ListViewCustomDrawItem(Sender: T CustomListView;510 procedure TListViewSort.ListViewCustomDrawItem(Sender: TDpiCustomListView; 494 511 Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean); 495 512 begin
Note:
See TracChangeset
for help on using the changeset viewer.