Bonjour,

presque tout est dans le titre. Suite à cette FAQ je me suis aperçu qu'une liste ne se triait pas (nuances : plus avec Rio, pas avec Sidney) si elle était filtrée par utilisation de la recherche d'où ma question.

ci-dessous les sources (code et forme)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
unit UTestSortList;
 
interface
 
uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  Data.Bind.GenData, Data.Bind.EngExt, Fmx.Bind.DBEngExt, System.Rtti,
  System.Bindings.Outputs, Fmx.Bind.Editors, FMX.Objects, Data.Bind.Components,
  FMX.Edit, FMX.SearchBox, FMX.Controls.Presentation, FMX.StdCtrls, FMX.Layouts,
  FMX.ListBox, Data.Bind.ObjectScope;
 
type
  TForm1 = class(TForm)
    PrototypeBindSource1: TPrototypeBindSource;
    ListBox1: TListBox;
    btnSortbyName: TButton;
    btnSortByBonus: TButton;
    SearchBox1: TSearchBox;
    BindingsList1: TBindingsList;
    LinkListControlToField1: TLinkListControlToField;
    PathSortN: TPath;
    PathSortB: TPath;
    procedure btnSortbyNameClick(Sender: TObject);
    procedure btnSortByBonusClick(Sender: TObject);
  private
    { Déclarations privées }
  public
    { Déclarations publiques }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.fmx}
 
uses System.Math;
 
procedure TForm1.btnSortByBonusClick(Sender: TObject);
var Compare : TFMXObjectSortCompare;
begin
{TODO -oOwner -cGeneral : tester si la liste est filtrée}
 PathSortN.Visible:=False;
 btnSortByBonus.Tag:=IfThen(btnSortByBonus.Tag=0,1,0);
 PathSortB.RotationAngle:=180*btnSortByBonus.Tag;
 PathSortB.Visible:=True;
 ListBox1.Sorted:=False;
 Compare:=function(Item1, Item2: TFmxObject): Integer
  var n1,n2 : Single;
  begin
    n1:=StrToFloatDef(TListBoxItem(Item1).ItemData.Detail,0);
    n2:=StrToFloatDef(TListBoxItem(Item2).ItemData.Detail,0);
    if n1=n2 then Result:=0
    else begin
      if n2>n1 then Result := 1
               else Result := -1;
    end;
    if btnSortByBonus.Tag=1 then Result:=Result*-1;
  end;
 ListBox1.Sort(Compare);
 ListBox1.RealignContent;
end;
 
procedure TForm1.btnSortbyNameClick(Sender: TObject);
var Compare : TFMXObjectSortCompare;
begin
{TODO -oOwner -cGeneral : tester si la liste est filtrée}
// si filtrée exit;
 PathSortB.Visible:=False;
 btnSortByName.Tag:=IfThen(btnSortByName.Tag=0,1,0);
 PathSortN.RotationAngle:=180*btnSortByName.Tag;
 PathSortN.Visible:=True;
 ListBox1.Sorted:=False;
 Compare:=function(Item1, Item2: TFmxObject): Integer
  begin
    result:=CompareText(TListBoxItem(Item1).text,TListBoxItem(Item2).text);
    if btnSortByName.Tag=1 then Result:=Result*-1;
  end;
 ListBox1.Sort(Compare);
 ListBox1.RealignContent;
end;
 
end.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
object Form1: TForm1
  Left = 0
  Top = 0
  Caption = ' ListBox Sort and Search'
  ClientHeight = 433
  ClientWidth = 383
  FormFactor.Width = 320
  FormFactor.Height = 480
  FormFactor.Devices = [Desktop]
  DesignerMasterStyle = 0
  object ListBox1: TListBox
    Position.X = 8.000000000000000000
    Position.Y = 72.000000000000000000
    Size.Width = 321.000000000000000000
    Size.Height = 297.000000000000000000
    Size.PlatformDefault = False
    DisableFocusEffect = True
    ItemIndex = 0
    Items.Strings = (
      'Mary Harris'
      'James Garcia'
      'Paul Davis'
      'Adam Brown'
      'Susan Sanchez'
      'Steve Moore'
      'Donna Martin'
      'Mark Anderson'
      'Michelle Smith'
      'Christine Jones')
    DefaultItemStyles.ItemStyle = 'listboxitemrightdetail'
    DefaultItemStyles.GroupHeaderStyle = ''
    DefaultItemStyles.GroupFooterStyle = ''
    Viewport.Width = 317.000000000000000000
    Viewport.Height = 271.000000000000000000
    object SearchBox1: TSearchBox
      Touch.InteractiveGestures = [LongTap, DoubleTap]
      Align = Top
      Size.Width = 317.000000000000000000
      Size.Height = 22.000000000000000000
      Size.PlatformDefault = False
    end
  end
  object btnSortbyName: TButton
    Position.X = 8.000000000000000000
    Position.Y = 384.000000000000000000
    Size.Width = 97.000000000000000000
    Size.Height = 33.000000000000000000
    Size.PlatformDefault = False
    Text = 'Sort by Name'
    OnClick = btnSortbyNameClick
  end
  object btnSortByBonus: TButton
    Position.X = 208.000000000000000000
    Position.Y = 384.000000000000000000
    Size.Width = 97.000000000000000000
    Size.Height = 33.000000000000000000
    Size.PlatformDefault = False
    Text = 'Sort by Bonus'
    OnClick = btnSortByBonusClick
  end
  object PathSortN: TPath
    Data.Path = {
      04000000000000000000803F0000A841010000000000B8410000A84101000000
      0000404100000040030000000000803F0000A841}
    Fill.Color = claBlack
    HitTest = False
    Position.X = 108.000000000000000000
    Position.Y = 388.000000000000000000
    Size.Width = 25.000000000000000000
    Size.Height = 25.000000000000000000
    Size.PlatformDefault = False
    Stroke.Kind = None
    Visible = False
  end
  object PathSortB: TPath
    Data.Path = {
      04000000000000000000803F0000A841010000000000B8410000A84101000000
      0000404100000040030000000000803F0000A841}
    Fill.Color = claBlack
    HitTest = False
    Position.X = 308.000000000000000000
    Position.Y = 388.000000000000000000
    Size.Width = 25.000000000000000000
    Size.Height = 25.000000000000000000
    Size.PlatformDefault = False
    Stroke.Kind = None
    Visible = False
  end
  object PrototypeBindSource1: TPrototypeBindSource
    AutoActivate = True
    AutoPost = False
    FieldDefs = <
      item
        Name = 'CName'
        Generator = 'ContactNames'
        Options = [optShuffle]
        ReadOnly = False
      end
      item
        Name = 'CBonus'
        FieldType = ftCurrency
        Generator = 'Currency'
        ReadOnly = False
      end>
    ScopeMappings = <>
    Left = 144
    Top = 8
  end
  object BindingsList1: TBindingsList
    Methods = <>
    OutputConverters = <>
    Left = 28
    Top = 5
    object LinkListControlToField1: TLinkListControlToField
      Category = 'Liaisons rapides'
      DataSource = PrototypeBindSource1
      FieldName = 'CName'
      Control = ListBox1
      FillExpressions = <
        item
          SourceMemberName = 'CBonus'
          ControlMemberName = 'Detail'
        end>
      FillHeaderExpressions = <>
      FillBreakGroups = <>
    end
  end
end
J'ai tenté la piste nombre d'items de la liste (-1 pour l'item de recherche) différent de nombre d'enregistrements mais, s'agissant d'un TProtypeBindSource ce n'est pas bon (RecordCount=-1)
et de toute façon je trouve ce test "limite"

D'autres idées ?