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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
| unit SearchListViewInterface;
interface
uses System.SysUtils, System.Types, System.Classes,
System.Generics.Collections,
FMX.ListView,
FMX.Dialogs;
type
TSearchMode = (smContains, smStartwith, smEndwith, smEqual);
ISearchInListView = interface
['{0AF62378-366E-4AED-9918-28F8BA5859A8}']
function Accept(const AFilter, AValue: string): Boolean;
function GetList: TListView;
procedure SetList(Value: TListView);
function GetCurrentIndice: SmallInt;
procedure SetCurrentIndice(Value: SmallInt);
function GetFields : TList<String>;
function GetTestFields: TList<String>;
procedure SetTestFields(Value: TList<String>);
function GetMode: TSearchMode;
procedure SetMode(Value: TSearchMode);
function GetCase: Boolean;
procedure SetCase(Value: Boolean);
property List: TListView read GetList write SetList;
property Fields: TList<String> read GetFields;
property CurrentIndice: SmallInt read GetCurrentIndice;
property TestFields: TList<String> read GetTestFields write SetTestFields;
property Mode: TSearchMode read GetMode write SetMode;
property CaseSensitive: Boolean read GetCase write SetCase;
end;
TISearchInListView = class(TInterfacedObject, ISearchInListView)
private
FList: TListView;
FFields: TList<String>;
FTests: TList<String>;
FCurrent: SmallInt;
FMax: SmallInt;
FMode: TSearchMode;
FCase: Boolean;
public
constructor Create(List : TListView );
destructor Destroy; override;
function Accept(const AFilter: string; const AValue: string): Boolean;
function GetCase: Boolean;
function GetCurrentIndice : SmallInt;
function GetList: TListView;
function GetMode: TSearchMode;
function GetTestFields: System.Generics.Collections.TList<System.string>;
procedure SetCase(Value: Boolean);
procedure SetCurrentIndice(Value: SmallInt);
procedure SetList(Value: TListView);
procedure SetMode(Value: TSearchMode);
procedure SetTestFields
(Value: System.Generics.Collections.TList<System.string>);
function GetFields : TList<String>;
end;
implementation
uses FMX.ListView.Types,
FMX.ListView.Appearances,
FMX.ListView.DynamicAppearance;
{ TISearchInListView }
function TISearchInListView.Accept(const AFilter, AValue: string): Boolean;
var
AVal, AFil, test: String;
begin
Result := True;
if AFilter.IsEmpty then
Exit;
AVal := AValue;
AFil := AFilter;
if not FCase then
begin
AVal := LowerCase(AValue);
AFil := LowerCase(AFilter);
end;
case FMode of
smContains:
Result := ((FTests.Count = 0) OR FTests.Contains(FFields.Items[FCurrent]))
AND AVal.Contains(AFil);
smStartwith:
Result := ((FTests.Count = 0) OR FTests.Contains(FFields.Items[FCurrent]))
AND AVal.StartsWith(AFil);
smEndwith:
Result := ((FTests.Count = 0) OR FTests.Contains(FFields.Items[FCurrent]))
AND AVal.EndsWith(AFil);
smEqual:
Result := ((FTests.Count = 0) OR FTests.Contains(FFields.Items[FCurrent]))
AND (AVal = AFil);
end;
if Result then
FCurrent := 0
else
inc(FCurrent);
if FCurrent > (FFields.Count-1) then
FCurrent := 0;
end;
constructor TISearchInListView.Create(List : TListView );
begin
SetList(List);
FTests:=TList<String>.Create;
FCurrent:=0;
FMode:=smContains;
FCase:=False;
end;
destructor TISearchInListView.Destroy;
begin
FFields.Free;
FTests.Free;
inherited;
end;
function TISearchInListView.GetCase: Boolean;
begin
Result := FCase;
end;
function TISearchInListView.GetCurrentIndice: SmallInt;
begin
Result := FCurrent;
end;
function TISearchInListView.GetFields: TList<String>;
begin
Result:= FFields;
end;
function TISearchInListView.GetList: TListView;
begin
Result := FList;
end;
function TISearchInListView.GetMode: TSearchMode;
begin
Result := FMode;
end;
function TISearchInListView.GetTestFields
: System.Generics.Collections.TList<System.string>;
begin
Result := FTests;
end;
procedure TISearchInListView.SetCase(Value: Boolean);
begin
if Value <> FCase then
FCase := Value;
end;
procedure TISearchInListView.SetCurrentIndice(Value: SmallInt);
begin
if Value <> FCurrent then
FCurrent := Value;
end;
procedure TISearchInListView.SetList(Value: TListView);
var
DynApp: TDynamicAppearance;
appObj: TCollectionItem;
begin
if Value <> FList then
begin
FList := Value;
if not Assigned(FFields) then
FFields := TList<String>.Create;
// obtenir les éléments texte
if FList.ItemAppearance.ItemAppearance = 'DynamicAppearance' then
begin
DynApp := TDynamicAppearance(FList.ItemAppearanceObjects.ItemObjects);
for appObj in DynApp.ObjectsCollection do
begin
if appObj is TAppearanceObjectItem then
if TAppearanceObjectItem(appObj).Appearance is TTextObjectAppearance
then
begin
inc(FMax);
FFields.Add(TAppearanceObjectItem(appObj).AppearanceObjectName);
end;
end;
end
else
begin
FMax:=0;
FFields.Add('text');
if LowerCase(FList.ItemAppearance.ItemAppearance).Contains('detail')
then begin
FFields.Add('detail');
FMax:=1;
end;
end;
end;
end;
procedure TISearchInListView.SetMode(Value: TSearchMode);
begin
FMode := Value;
end;
procedure TISearchInListView.SetTestFields
(Value: System.Generics.Collections.TList<System.string>);
begin
if not Assigned(FTests) then
FTests := TList<string>.Create;
FTests := Value;
end;
end. |
Partager