Ignore:
Timestamp:
Jun 7, 2024, 11:59:43 AM (3 months ago)
Author:
chronos
Message:
  • Modified: Updated Common package.
File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/ListViewSort.pas

    r84 r85  
    1 unit UListViewSort;
     1unit ListViewSort;
    22
    33// Date: 2019-05-17
    4 
    5 {$mode delphi}
    64
    75interface
     
    97uses
    108  {$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;
    1311
    1412type
     
    1917  TCompareEvent = function (Item1, Item2: TObject): Integer of object;
    2018  TListFilterEvent = procedure (ListViewSort: TListViewSort) of object;
     19
     20  TObjects = TObjectList<TObject>;
    2121
    2222  { TListViewSort }
     
    5252    {$ENDIF}
    5353  public
    54     List: TFPGObjectList<TObject>;
    55     Source: TFPGObjectList<TObject>;
     54    Source: TObjects;
     55    List: TObjects;
    5656    constructor Create(AOwner: TComponent); override;
    5757    destructor Destroy; override;
     
    8181    FOnChange: TNotifyEvent;
    8282    FStringGrid1: TStringGrid;
     83    procedure DoOnChange;
    8384    procedure GridDoOnKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    8485    procedure GridDoOnResize(Sender: TObject);
     
    9091    function TextEnteredColumn(Index: Integer): Boolean;
    9192    function GetColValue(Index: Integer): string;
     93    procedure Reset;
    9294    property StringGrid: TStringGrid read FStringGrid1 write FStringGrid1;
    9395  published
     
    147149destructor TListViewEx.Destroy;
    148150begin
    149   inherited Destroy;
     151  inherited;
    150152end;
    151153
    152154{ TListViewFilter }
     155
     156procedure TListViewFilter.DoOnChange;
     157begin
     158  if Assigned(FOnChange) then FOnChange(Self);
     159end;
    153160
    154161procedure TListViewFilter.GridDoOnKeyUp(Sender: TObject; var Key: Word;
    155162  Shift: TShiftState);
    156163begin
    157   if Assigned(FOnChange) then
    158     FOnChange(Self);
     164  DoOnChange;
    159165end;
    160166
     
    229235end;
    230236
     237procedure TListViewFilter.Reset;
     238var
     239  I: Integer;
     240begin
     241  with StringGrid do
     242  for I := 0 to ColCount - 1 do
     243    Cells[I, 0] := '';
     244  DoOnChange;
     245end;
     246
    231247{ TListViewSort }
    232248
     
    322338  ListViewSortCompare: TCompareEvent;
    323339
    324 function ListViewCompare(const Item1, Item2: TObject): Integer;
     340function ListViewCompare(constref Item1, Item2: TObject): Integer;
    325341begin
    326342  Result := ListViewSortCompare(Item1, Item2);
     
    333349  ListViewSortCompare := Compare;
    334350  if (List.Count > 0) then
    335     List.Sort(ListViewCompare);
     351    List.Sort(TComparer<TObject>.Construct(ListViewCompare));
    336352end;
    337353
     
    339355begin
    340356  if Assigned(FOnFilter) then FOnFilter(Self)
    341   else if Assigned(Source) then
    342     List.Assign(Source) else
     357  else if Assigned(Source) then begin
    343358    List.Clear;
     359    List.AddRange(Source);
     360  end else List.Clear;
    344361  if ListView.Items.Count <> List.Count then
    345362    ListView.Items.Count := List.Count;
     
    396413begin
    397414  inherited;
    398   List := TFPGObjectList<TObject>.Create;
    399   List.FreeObjects := False;
     415  List := TObjects.Create;
     416  List.OwnsObjects := False;
    400417end;
    401418
    402419destructor TListViewSort.Destroy;
    403420begin
    404   List.Free;
     421  FreeAndNil(List);
    405422  inherited;
    406423end;
Note: See TracChangeset for help on using the changeset viewer.