Ignore:
Timestamp:
Mar 18, 2022, 1:37:03 PM (3 years ago)
Author:
chronos
Message:
  • Modified: Update Common package.
File:
1 edited

Legend:

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

    r122 r131  
    11unit UListViewSort;
    22
    3 // Date: 2010-11-03
     3// Date: 2019-05-17
    44
    55{$mode delphi}
     
    88
    99uses
    10   {$IFDEF Windows}Windows, CommCtrl, {$ENDIF}Classes, Graphics, ComCtrls, SysUtils,
    11   Controls, DateUtils, Dialogs, SpecializedList, Forms, Grids, StdCtrls, ExtCtrls,
    12   LclIntf, LMessages, LclType, LResources;
     10  {$IFDEF Windows}Windows, CommCtrl, LMessages, {$ENDIF}Classes, Graphics, ComCtrls, SysUtils,
     11  Controls, DateUtils, Dialogs, fgl, Forms, Grids, StdCtrls, ExtCtrls,
     12  LclIntf, LclType, LResources;
    1313
    1414type
     
    5252    {$ENDIF}
    5353  public
    54     List: TListObject;
    55     Source: TListObject;
     54    List: TFPGObjectList<TObject>;
     55    Source: TFPGObjectList<TObject>;
    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
     
    98100  end;
    99101
     102  { TListViewEx }
     103
     104  TListViewEx = class(TWinControl)
     105  private
     106    FFilter: TListViewFilter;
     107    FListView: TListView;
     108    FListViewSort: TListViewSort;
     109    procedure ResizeHanlder;
     110  public
     111    constructor Create(TheOwner: TComponent); override;
     112    destructor Destroy; override;
     113  published
     114    property ListView: TListView read FListView write FListView;
     115    property ListViewSort: TListViewSort read FListViewSort write FListViewSort;
     116    property Filter: TListViewFilter read FFilter write FFilter;
     117    property Visible;
     118  end;
     119
    100120procedure Register;
    101121
     
    105125procedure Register;
    106126begin
    107   RegisterComponents('Common', [TListViewSort, TListViewFilter]);
     127  RegisterComponents('Common', [TListViewSort, TListViewFilter, TListViewEx]);
     128end;
     129
     130{ TListViewEx }
     131
     132procedure TListViewEx.ResizeHanlder;
     133begin
     134end;
     135
     136constructor TListViewEx.Create(TheOwner: TComponent);
     137begin
     138  inherited Create(TheOwner);
     139  Filter := TListViewFilter.Create(Self);
     140  Filter.Parent := Self;
     141  Filter.Align := alBottom;
     142  ListView := TListView.Create(Self);
     143  ListView.Parent := Self;
     144  ListView.Align := alClient;
     145  ListViewSort := TListViewSort.Create(Self);
     146  ListViewSort.ListView := ListView;
     147end;
     148
     149destructor TListViewEx.Destroy;
     150begin
     151  inherited Destroy;
    108152end;
    109153
    110154{ TListViewFilter }
     155
     156procedure TListViewFilter.DoOnChange;
     157begin
     158  if Assigned(FOnChange) then FOnChange(Self);
     159end;
    111160
    112161procedure TListViewFilter.GridDoOnKeyUp(Sender: TObject; var Key: Word;
    113162  Shift: TShiftState);
    114163begin
    115   if Assigned(FOnChange) then
    116     FOnChange(Self);
     164  DoOnChange;
    117165end;
    118166
     
    187235end;
    188236
     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
    189247{ TListViewSort }
    190248
     
    277335end;
    278336
     337var
     338  ListViewSortCompare: TCompareEvent;
     339
     340function ListViewCompare(const Item1, Item2: TObject): Integer;
     341begin
     342  Result := ListViewSortCompare(Item1, Item2);
     343end;
     344
    279345procedure TListViewSort.Sort(Compare: TCompareEvent);
    280346begin
     347  // TODO: Because TFLGObjectList compare handler is not class method,
     348  // it is necessary to use simple function compare handler with local variable
     349  ListViewSortCompare := Compare;
    281350  if (List.Count > 0) then
    282     List.Sort(Compare);
     351    List.Sort(ListViewCompare);
    283352end;
    284353
     
    343412begin
    344413  inherited;
    345   List := TListObject.Create;
    346   List.OwnsObjects := False;
     414  List := TFPGObjectList<TObject>.Create;
     415  List.FreeObjects := False;
    347416end;
    348417
Note: See TracChangeset for help on using the changeset viewer.