Add an example project for FilterEdits. Issue #40035, modified from patch by dbannon.

This commit is contained in:
Juha 2022-12-11 18:36:26 +02:00
parent 5f4aa96422
commit be093cd40d
13 changed files with 663 additions and 0 deletions

View File

@ -0,0 +1,5 @@
{ "FilterEditsDemo" : {
"Category" : "General",
"Keywords" : ["ListBox", "ListView", "TreeView", "Filter", "Search Here"],
"Description" : "An Example project to demonstrate use of FilterEdit components, namely ListFilterEdit, ListViewFilterEdit and TreeFilterEdit. They provide a simple means to filter ListBox, ListView and TreeView contents respectively.\n\nSee also https://wiki.freepascal.org/TListFilterEdit, wiki.freepascal.org/TListViewFilterEdit, wiki.freepascal.org/TTreeFilterEdit"}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

View File

@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<General>
<SessionStorage Value="InProjectDir"/>
<Title Value="filtereditsdemo"/>
<Scaled Value="True"/>
<ResourceType Value="res"/>
<UseXPManifest Value="True"/>
<XPManifest>
<DpiAware Value="True"/>
</XPManifest>
<Icon Value="0"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<DestinationDirectory Value="$(ProjPath)/published/"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<RequiredPackages>
<Item>
<PackageName Value="LCL"/>
</Item>
<Item>
<PackageName Value="LazControls"/>
</Item>
<Item>
<PackageName Value="LazControlDsgn"/>
</Item>
</RequiredPackages>
<Units>
<Unit>
<Filename Value="filtereditsdemo.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="FilterEditsDemo"/>
</Unit>
<Unit>
<Filename Value="mainunit.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="MainForm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="MainUnit"/>
</Unit>
<Unit>
<Filename Value="listviewfilterunit.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="ListViewFilterForm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="ListViewFilterUnit"/>
</Unit>
<Unit>
<Filename Value="listfilterunit.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="ListFilterForm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="ListFilterUnit"/>
</Unit>
<Unit>
<Filename Value="treefilterunit.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="TreeFilterForm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="TreeFilterUnit"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<Target>
<Filename Value="filtereditsdemo"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
</CompilerOptions>
</CONFIG>

View File

@ -0,0 +1,28 @@
program FilterEditsDemo;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
{$IFDEF HASAMIGA}
athreads,
{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, LazControls, MainUnit, ListViewFilterUnit, ListFilterUnit,
TreeFilterUnit;
{$R *.res}
begin
RequireDerivedFormResource:=True;
Application.Scaled:=True;
Application.Initialize;
Application.CreateForm(TMainForm, MainForm);
Application.CreateForm(TListFilterForm, ListFilterForm);
Application.CreateForm(TListViewFilterForm, ListViewFilterForm);
Application.CreateForm(TTreeFilterForm, TreeFilterForm);
Application.Run;
end.

Binary file not shown.

View File

@ -0,0 +1,23 @@
object ListFilterForm: TListFilterForm
Left = 141
Height = 240
Top = 206
Width = 320
Caption = 'ListFilterForm'
ClientHeight = 240
ClientWidth = 320
LCLVersion = '2.3.0.0'
object Label1: TLabel
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Owner
Left = 20
Height = 19
Top = 20
Width = 193
BorderSpacing.Left = 20
BorderSpacing.Top = 20
Caption = 'ListFilterEdit Example (ToDo)'
Font.Style = [fsBold]
ParentFont = False
end
end

View File

@ -0,0 +1,50 @@
{
***************************************************************************
* *
* This source is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This code is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* A copy of the GNU General Public License is available on the World *
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
* obtain it by writing to the Free Software Foundation, *
* Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA. *
* *
***************************************************************************
}
unit ListFilterUnit;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TListFilterForm }
TListFilterForm = class(TForm)
Label1: TLabel;
private
public
end;
var
ListFilterForm: TListFilterForm;
implementation
{$R *.lfm}
end.

View File

@ -0,0 +1,124 @@
object ListViewFilterForm: TListViewFilterForm
Left = 472
Height = 408
Top = 253
Width = 469
Caption = 'ListViewFilterForm'
ClientHeight = 408
ClientWidth = 469
OnCreate = FormCreate
LCLVersion = '2.3.0.0'
object ButtonProgram: TButton
AnchorSideLeft.Control = ListViewFilterEdit1
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = ListViewFilterEdit1
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = CheckCaseSensitive
Left = 20
Height = 25
Top = 281
Width = 429
Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Top = 20
BorderSpacing.Bottom = 20
Caption = 'programmatically x'
OnClick = ButtonProgramClick
TabOrder = 0
end
object ListView1: TListView
AnchorSideLeft.Control = ListViewFilterEdit1
AnchorSideTop.Control = ListViewFilterEdit1
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = ListViewFilterEdit1
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ButtonProgram
Left = 20
Height = 151
Top = 110
Width = 429
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Top = 20
BorderSpacing.Bottom = 20
Columns = <
item
AutoSize = True
Caption = 'Col 1'
Width = 42
end
item
Caption = 'Col 2'
Width = 365
end>
SortColumn = 0
SortType = stText
TabOrder = 1
ViewStyle = vsReport
end
object CheckCaseSensitive: TCheckBox
AnchorSideLeft.Control = ListViewFilterEdit1
AnchorSideTop.Side = asrBottom
AnchorSideBottom.Control = CheckBothColumns
Left = 20
Height = 21
Top = 326
Width = 112
Anchors = [akLeft, akBottom]
BorderSpacing.Top = 20
BorderSpacing.Bottom = 20
Caption = 'Case Sensitive'
OnChange = CheckCaseSensitiveChange
TabOrder = 2
end
object ListViewFilterEdit1: TListViewFilterEdit
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Label1
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 20
Height = 31
Top = 59
Width = 429
CharCase = ecNormal
ButtonWidth = 23
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 20
BorderSpacing.Top = 20
BorderSpacing.Right = 20
NumGlyphs = 1
MaxLength = 0
TabOrder = 3
Text = 'listviewfilteredit1'
TextHint = 'Search Here'
FilteredListview = ListView1
end
object CheckBothColumns: TCheckBox
AnchorSideLeft.Control = ListViewFilterEdit1
AnchorSideTop.Side = asrBottom
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 20
Height = 21
Top = 367
Width = 110
Anchors = [akLeft, akBottom]
BorderSpacing.Top = 20
BorderSpacing.Bottom = 20
Caption = 'Both Columns'
OnChange = CheckBothColumnsChange
TabOrder = 4
end
object Label1: TLabel
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Owner
Left = 20
Height = 19
Top = 20
Width = 179
BorderSpacing.Left = 20
BorderSpacing.Top = 20
Caption = 'ListViewFilterEdit Example'
Font.Style = [fsBold]
ParentFont = False
end
end

View File

@ -0,0 +1,129 @@
{
***************************************************************************
* *
* This source is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This code is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* A copy of the GNU General Public License is available on the World *
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
* obtain it by writing to the Free Software Foundation, *
* Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA. *
* *
***************************************************************************
}
unit ListViewFilterUnit;
{$mode objfpc}{$H+}
{ An Example project to demonstrate use of the ListViewFilterEdit
component, a simple means to filter ListView contents.
Content to be displayed in the ListView must be loaded via the ListViewFilterEdit
control. Although not demonstrated here, its possible to include an object with
each row, much the same as can be done with ListView.
There does not appear to be a way to define an external search method. Therefore
you can search only the content actually loaded into the TListViewFilterEdit.
Do not use a ListViewFilterEdit with a ListView in Owner Data mode.
FilterOptions property should be used to make filtering case sensitive or not.
Following changes were made in the Object Inspector -
ListView1.ViewStyle := vsReport;
ListViewFilterEdit1.FilteredListview := ListView1;
ListViewFilterEdit1.TextHint := 'Search Here';
ListViewFilterEdit1.CharCase := ecNormal;
Create two columns in the ListView, set first one to be autowidth
David Bannon, 2022-12-07
}
interface
uses
Forms, Controls, StdCtrls, ComCtrls,
ListViewFilterEdit, EditBtn;
type
{ TListViewFilterForm }
TListViewFilterForm = class(TForm)
ButtonProgram: TButton;
CheckBothColumns: TCheckBox;
CheckCaseSensitive: TCheckBox;
Label1: TLabel;
ListView1: TListView;
ListViewFilterEdit1: TListViewFilterEdit;
procedure ButtonProgramClick(Sender: TObject);
procedure CheckBothColumnsChange(Sender: TObject);
procedure CheckCaseSensitiveChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
procedure AddLVItem(St1, St2: string);
public
end;
var
ListViewFilterForm: TListViewFilterForm;
implementation
{$R *.lfm}
procedure TListViewFilterForm.AddLVItem(St1, St2 : string);
var
ListItem: TListViewDataItem;
begin
ListItem.Data := Nil;
SetLength(ListItem.StringArray, 2);
ListItem.StringArray[0] := St1;
ListItem.StringArray[1] := St2;
{%H-}ListViewFilterEdit1.Items.Add(ListItem);
end;
procedure TListViewFilterForm.FormCreate(Sender: TObject);
begin
ListView1.BeginUpdate;
AddLVItem('String1', 'String2');
AddLVItem('String3', 'String4');
AddLVItem('A String', 'another String');
AddLVItem('x string', 'Extra String');
ListViewFilterEdit1.InvalidateFilter;
ListViewFilterEdit1.ResetFilter;
ListView1.EndUpdate;
end;
procedure TListViewFilterForm.ButtonProgramClick(Sender: TObject);
begin
ListViewFilterEdit1.Filter := 'x'; // Filter for strings containing x
end;
procedure TListViewFilterForm.CheckBothColumnsChange(Sender: TObject);
begin
ListViewFilterEdit1.ByAllFields := CheckBothColumns.Checked;
end;
procedure TListViewFilterForm.CheckCaseSensitiveChange(Sender: TObject);
begin
with ListViewFilterEdit1 do
if CheckCaseSensitive.checked then
FilterOptions := FilterOptions + [fsoCaseSensitive]
else
FilterOptions := FilterOptions - [fsoCaseSensitive];
end;
end.

View File

@ -0,0 +1,51 @@
object MainForm: TMainForm
Left = 514
Height = 207
Top = 51
Width = 268
Caption = 'MainForm'
ClientHeight = 207
ClientWidth = 268
OnCreate = FormCreate
LCLVersion = '2.3.0.0'
object Label1: TLabel
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Owner
Left = 20
Height = 19
Top = 20
Width = 126
BorderSpacing.Left = 20
BorderSpacing.Top = 20
Caption = 'FilterEdit Examples'
Font.Style = [fsBold]
ParentFont = False
end
object ListFilterEditButton: TButton
Left = 20
Height = 25
Top = 56
Width = 220
Caption = 'ListFilterEdit'
OnClick = ListFilterEditButtonClick
TabOrder = 0
end
object ListViewFilterEditButton: TButton
Left = 20
Height = 25
Top = 96
Width = 220
Caption = 'ListViewFilterEdit'
OnClick = ListViewFilterEditButtonClick
TabOrder = 1
end
object TreeFilterEditButton: TButton
Left = 20
Height = 25
Top = 136
Width = 220
Caption = 'TreeFilterEdit'
OnClick = TreeFilterEditButtonClick
TabOrder = 2
end
end

View File

@ -0,0 +1,85 @@
{
***************************************************************************
* *
* This source is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This code is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* A copy of the GNU General Public License is available on the World *
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
* obtain it by writing to the Free Software Foundation, *
* Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA. *
* *
***************************************************************************
}
unit MainUnit;
{$mode objfpc}{$H+}
{
An Example project to demonstrate use of FilterEdit components.
They provide a simple means to filter ListBox, ListView and TreeView contents.
David Bannon, Juha Manninen
}
interface
uses
Forms, Controls, StdCtrls,
ListFilterUnit, ListViewFilterUnit, TreeFilterUnit;
type
{ TMainForm }
TMainForm = class(TForm)
ListFilterEditButton: TButton;
ListViewFilterEditButton: TButton;
TreeFilterEditButton: TButton;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure ListFilterEditButtonClick(Sender: TObject);
procedure ListViewFilterEditButtonClick(Sender: TObject);
procedure TreeFilterEditButtonClick(Sender: TObject);
private
public
end;
var
MainForm: TMainForm;
implementation
{$R *.lfm}
procedure TMainForm.FormCreate(Sender: TObject);
begin
;
end;
procedure TMainForm.ListFilterEditButtonClick(Sender: TObject);
begin
ListFilterForm.Show;
end;
procedure TMainForm.ListViewFilterEditButtonClick(Sender: TObject);
begin
ListViewFilterForm.Show;
end;
procedure TMainForm.TreeFilterEditButtonClick(Sender: TObject);
begin
TreeFilterForm.Show;
end;
end.

View File

@ -0,0 +1,23 @@
object TreeFilterForm: TTreeFilterForm
Left = 969
Height = 240
Top = 209
Width = 320
Caption = 'TreeFilterForm'
ClientHeight = 240
ClientWidth = 320
LCLVersion = '2.3.0.0'
object Label1: TLabel
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Owner
Left = 20
Height = 19
Top = 20
Width = 197
BorderSpacing.Left = 20
BorderSpacing.Top = 20
Caption = 'TreeFilterEdit Example (ToDo)'
Font.Style = [fsBold]
ParentFont = False
end
end

View File

@ -0,0 +1,50 @@
{
***************************************************************************
* *
* This source is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This code is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* A copy of the GNU General Public License is available on the World *
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
* obtain it by writing to the Free Software Foundation, *
* Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA. *
* *
***************************************************************************
}
unit TreeFilterUnit;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TTreeFilterForm }
TTreeFilterForm = class(TForm)
Label1: TLabel;
private
public
end;
var
TreeFilterForm: TTreeFilterForm;
implementation
{$R *.lfm}
end.