Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: No effect after set TDataSet's Filtered to true


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 10 - Last Post: Apr 18, 2015 4:50 PM Last Post By: George Wei
George Wei

Posts: 40
Registered: 9/18/05
No effect after set TDataSet's Filtered to true  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 6, 2015 3:49 PM
Dear all,

In my application, I have to manually make a TStringGrid db-aware as follows:

class procedure TStringGridLiveBindHelper.DoBind(Instance: TObject;
  DataSource: TBindSourceDB; const ColDict: TColDict);
var
  Grid: TStringGrid;
  bl: TBindingsList;
  DataSet: TDataSet;
  Link: TLinkGridToDataSource;
  LinkColumn: TLinkGridToDataSourceColumn;
  ColProperties: TColProperties;
begin
  inherited;
  Grid := Instance as TStringGrid;
  DataSet := DataSource.DataSet;
  bl := TBindingsList.Create(DataSource);
  Link := TLinkGridToDataSource.Create(bl);
  Link.DataSource := DataSource;
  Link.GridControl := Grid;
  Link.BeginLayout;
  try
    for ColProperties in ColDict do //TColProperties & TColDict are customized types to keep column properties
      //if ColName <> '' then
      //begin
        if DataSet.FindField(ColProperties.Name) <> nil then
        begin
          LinkColumn := Link.Columns.Add;
          LinkColumn.MemberName := ColProperties.Name;
          LinkColumn.Visible := ColProperties.Visible;
          LinkColumn.Header := ColProperties.Header;
        end
        else
          GetLogger.Warn('Column '''+ColProperties.Name+''' not found in dataset');
      //end;
  finally
    Link.EndLayout;
  end;
  Link.Active := True;
end;


After TStringGridLiveBindHelper.DoBind executed, all records show in the TStringGrid object with chosen columns correctly.

Then, I filter the dataset as follows:

procedure TSearchManager.DoSearch;
begin
  FDataSet.DisableControls;
  try
    FDataSet.Filtered := False;
    FDataSet.FilterOptions := FDataSet.FilterOptions + [foCaseInsensitive];
    if FFilterStr <> '' then
    begin
      FDataSet.Filter := FFilterStr;
      FDataSet.Filtered := True;
    end;
  finally
    FDataSet.EnableControls;
  end;
end;


But no records are filtered in the TStringGrid object after TSearchManager.DoSearch executed. What's the problem?

Regards,
George
George Wei

Posts: 40
Registered: 9/18/05
Re: No effect after set TDataSet's Filtered to true  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 7, 2015 6:42 AM   in response to: George Wei in response to: George Wei
I've tried another test for comparison:

1 Drop FDConnection1, FDQuery1, BindSourceDB1 & StringGrid1 onto a form
2 Tune FDConnection1 & FDQuery1 object, and activate the later one
3 Right click BindSourceDB1 & Bind Visually
4 Drop Edit1 & Button1 onto the form, write a OnClick event handler for the Button1 as follows:

procedure TForm1.Button1Click(Sender: TObject);
begin
  if Edit1.Text <> '' then
  begin
    with FDQuery1 do
    begin
      Filtered := False;
      Filter := 'Name_pinyin like ''%'+Edit1.Text+'%'''; //Name_pinyin is one of the field of FDQuery1
      Filtered := True;
    end;
  end;
end;


5 Run the application, type some text in Edit1, then click Button1. Nothing happens! No records filtered!

This is the simplest way to make a TStringGrid db-aware. But is it really db-aware? Or is there something wrong of my test?

Regards,
George
Jeff Overcash (...

Posts: 1,529
Registered: 9/23/99
Re: No effect after set TDataSet's Filtered to true  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 7, 2015 9:58 AM   in response to: George Wei in response to: George Wei
Since this has nothing to do with FireMonkey I suggest you ask it in the
database/FireDAC group where the developer answers a lot of questions.

George Wei wrote:
I've tried another test for comparison:

1 Drop FDConnection1, FDQuery1, BindSourceDB1 & StringGrid1 onto a form
2 Tune FDConnection1 & FDQuery1 object, and activate the later one
3 Right click BindSourceDB1 & Bind Visually
4 Drop Edit1 & Button1 onto the form, write a OnClick event handler for the Button1 as follows:

procedure TForm1.Button1Click(Sender: TObject);
begin
  if Edit1.Text <> '' then
  begin
    with FDQuery1 do
    begin
      Filtered := False;
      Filter := 'Name_pinyin like ''%'+Edit1.Text+'%'''; //Name_pinyin is one of the field of FDQuery1
      Filtered := True;
    end;
  end;
end;


5 Run the application, type some text in Edit1, then click Button1. Nothing happens! No records filtered!

This is the simplest way to make a TStringGrid db-aware. But is it really db-aware? Or is there something wrong of my test?

Regards,
George

--
Jeff Overcash (TeamB)
(Please do not email me directly unless asked. Thank You)
And so I patrol in the valley of the shadow of the tricolor
I must fear evil. For I am but mortal and mortals can only die.
Asking questions, pleading answers from the nameless
faceless watchers that stalk the carpeted corridors of Whitehall.
(Fish)

Lajos Juhasz

Posts: 801
Registered: 3/14/14
Re: No effect after set TDataSet's Filtered to true  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 7, 2015 1:25 PM   in response to: George Wei in response to: George Wei
George Wei wrote:

is the simplest way to make a TStringGrid db-aware. But is it
really db-aware? Or is there something wrong of my test?

I have tried:

FDQuery1.Filter:='some_field like ''L%''';
FDQuery1.filtered:=true;


After this code the stringgrid shows only the filtered records.
George Wei

Posts: 40
Registered: 9/18/05
Re: No effect after set TDataSet's Filtered to true  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 7, 2015 3:25 PM   in response to: Lajos Juhasz in response to: Lajos Juhasz
I changed the filter string assignment statement like what you do, but it's non-useful.

Filter := 'Name_pinyin like '''+Edit1.Text+'%''';


George
Lajos Juhasz wrote:
George Wei wrote:

is the simplest way to make a TStringGrid db-aware. But is it
really db-aware? Or is there something wrong of my test?

I have tried:

FDQuery1.Filter:='some_field like ''L%''';
FDQuery1.filtered:=true;


After this code the stringgrid shows only the filtered records.
George Wei

Posts: 40
Registered: 9/18/05
Re: No effect after set TDataSet's Filtered to true  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 10, 2015 4:23 PM   in response to: George Wei in response to: George Wei
As my test result, this issue occurs in a Multi-Device Application, not in a VCL Forms Application. Is this a bug of FireMonkey?
Linden ROTH

Posts: 467
Registered: 11/3/11
Re: No effect after set TDataSet's Filtered to true  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 10, 2015 7:49 PM   in response to: George Wei in response to: George Wei
George Wei wrote:
As my test result, this issue occurs in a Multi-Device Application, not in a VCL Forms Application. Is this a bug of FireMonkey?

Perhaps it would be good to refresh the grid .... after the filter is applied ....
--
Linden
"Mango" was Cool but "Wasabi" was Hotter but remember it's all in the "source"
George Wei

Posts: 40
Registered: 9/18/05
Re: No effect after set TDataSet's Filtered to true  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 10, 2015 9:30 PM   in response to: Linden ROTH in response to: Linden ROTH
How can I do that? I've tried some methods, but they all do not take effect.

George
Linden ROTH wrote:
George Wei wrote:
As my test result, this issue occurs in a Multi-Device Application, not in a VCL Forms Application. Is this a bug of FireMonkey?

Perhaps it would be good to refresh the grid .... after the filter is applied ....
--
Linden
"Mango" was Cool but "Wasabi" was Hotter but remember it's all in the "source"
Linden ROTH

Posts: 467
Registered: 11/3/11
Re: No effect after set TDataSet's Filtered to true  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 11, 2015 12:40 AM   in response to: George Wei in response to: George Wei
George Wei wrote:
How can I do that? I've tried some methods, but they all do not take effect.

George
Linden ROTH wrote:
George Wei wrote:
As my test result, this issue occurs in a Multi-Device Application, not in a VCL Forms Application. Is this a bug of FireMonkey?

Perhaps it would be good to refresh the grid .... after the filter is applied ....
--
Linden
"Mango" was Cool but "Wasabi" was Hotter but remember it's all in the "source"

OK ignore what I said ...

Here is a complete one that works...

NB you said drop a bindSource and then bind visually ... That adds an additional BindSource
unit Unit12;
 
interface
 
uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FireDAC.Stan.Intf, FireDAC.Stan.Option,
  FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async,
  FireDAC.Phys, FireDAC.Phys.IB, FireDAC.Phys.IBDef, FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt,
  System.Rtti, Data.Bind.EngExt, Fmx.Bind.DBEngExt, Fmx.Bind.Grid, System.Bindings.Outputs, Fmx.Bind.Editors,
  FMX.Controls.Presentation, FMX.Edit, FMX.StdCtrls, Data.Bind.Components, Data.Bind.Grid, Data.Bind.DBScope,
  FMX.Layouts, FMX.Grid, Data.DB, FireDAC.Comp.DataSet, FireDAC.Comp.Client, FireDAC.FMXUI.Wait, FireDAC.Comp.UI;
 
type
  TForm12 = class(TForm)
    FDConnection1: TFDConnection;
    FDQuery1: TFDQuery;
    StringGrid1: TStringGrid;
    BindSourceDB1: TBindSourceDB;
    BindingsList1: TBindingsList;
    LinkGridToDataSourceBindSourceDB1: TLinkGridToDataSource;
    Button1: TButton;
    Edit1: TEdit;
    FDGUIxWaitCursor1: TFDGUIxWaitCursor;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form12: TForm12;
 
implementation
 
{$R *.fmx}
 
procedure TForm12.Button1Click(Sender: TObject);
begin
 if Edit1.Text <> '' then
  begin
    with FDQuery1 do
    begin
      Filtered := False;
      Filter := 'EMPNO like ''%'+Edit1.Text+'%'''; //Name_pinyin is one of the field of FDQuery1
      Filtered := True;
    end;
  end;
 
end;
 
end.

//FMX
object Form12: TForm12
  Left = 0
  Top = 0
  Caption = 'Form12'
  ClientHeight = 480
  ClientWidth = 640
  FormFactor.Width = 320
  FormFactor.Height = 480
  FormFactor.Devices = [Desktop]
  DesignerMasterStyle = 0
  object StringGrid1: TStringGrid
    Position.X = 32.000000000000000000
    Position.Y = 120.000000000000000000
    Size.Width = 577.000000000000000000
    Size.Height = 313.000000000000000000
    Size.PlatformDefault = False
    TabOrder = 4
    RowCount = 42
    RowHeight = 21.000000000000000000
  end
  object Button1: TButton
    Position.X = 464.000000000000000000
    Position.Y = 48.000000000000000000
    TabOrder = 9
    Text = 'Button1'
    OnClick = Button1Click
  end
  object Edit1: TEdit
    Touch.InteractiveGestures = [LongTap, DoubleTap]
    TabOrder = 10
    Position.X = 328.000000000000000000
    Position.Y = 8.000000000000000000
  end
  object FDConnection1: TFDConnection
    Params.Strings = (
      
        'Database=D:\Users\Public\Documents\Embarcadero\Studio\15.0\Sampl' +
        'es\Data\dbdemos.gdb'
      'User_Name=SYSDBA'
      'Password=masterkey'
      'DriverID=IB')
    Connected = True
    LoginPrompt = False
    Left = 96
    Top = 48
  end
  object FDQuery1: TFDQuery
    Active = True
    Connection = FDConnection1
    SQL.Strings = (
      'select * from employee')
    Left = 216
    Top = 48
  end
  object BindSourceDB1: TBindSourceDB
    DataSet = FDQuery1
    ScopeMappings = <>
    Left = 384
    Top = 48
  end
  object BindingsList1: TBindingsList
    Methods = <>
    OutputConverters = <>
    Left = 20
    Top = 5
    object LinkGridToDataSourceBindSourceDB1: TLinkGridToDataSource
      Category = 'Quick Bindings'
      DataSource = BindSourceDB1
      GridControl = StringGrid1
      Columns = <>
    end
  end
  object FDGUIxWaitCursor1: TFDGUIxWaitCursor
    Provider = 'FMX'
    Left = 528
    Top = 88
  end
end


--
Linden
"Mango" was Cool but "Wasabi" was Hotter but remember it's all in the "source"
George Wei

Posts: 40
Registered: 9/18/05
Re: No effect after set TDataSet's Filtered to true  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 13, 2015 3:21 PM   in response to: Linden ROTH in response to: Linden ROTH
I've checked your code, it has no essential difference with my code except the database SQLite I'm using.

I copied your code into my project, and I just changed the following properties/statements:

1 FDConnection1's Params.Strings,
2 FDQuery1's SQL.Strings,
3 Filter assignment statement in procedure TForm12.Button1Click

The test result is as the same as my original code. I'm puzzled why the same code works differently.

Linden ROTH wrote:
OK ignore what I said ...

Here is a complete one that works...

NB you said drop a bindSource and then bind visually ... That adds an additional BindSource
unit Unit12;
 
interface
 
uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FireDAC.Stan.Intf, FireDAC.Stan.Option,
  FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async,
  FireDAC.Phys, FireDAC.Phys.IB, FireDAC.Phys.IBDef, FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt,
  System.Rtti, Data.Bind.EngExt, Fmx.Bind.DBEngExt, Fmx.Bind.Grid, System.Bindings.Outputs, Fmx.Bind.Editors,
  FMX.Controls.Presentation, FMX.Edit, FMX.StdCtrls, Data.Bind.Components, Data.Bind.Grid, Data.Bind.DBScope,
  FMX.Layouts, FMX.Grid, Data.DB, FireDAC.Comp.DataSet, FireDAC.Comp.Client, FireDAC.FMXUI.Wait, FireDAC.Comp.UI;
 
type
  TForm12 = class(TForm)
    FDConnection1: TFDConnection;
    FDQuery1: TFDQuery;
    StringGrid1: TStringGrid;
    BindSourceDB1: TBindSourceDB;
    BindingsList1: TBindingsList;
    LinkGridToDataSourceBindSourceDB1: TLinkGridToDataSource;
    Button1: TButton;
    Edit1: TEdit;
    FDGUIxWaitCursor1: TFDGUIxWaitCursor;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form12: TForm12;
 
implementation
 
{$R *.fmx}
 
procedure TForm12.Button1Click(Sender: TObject);
begin
 if Edit1.Text <> '' then
  begin
    with FDQuery1 do
    begin
      Filtered := False;
      Filter := 'EMPNO like ''%'+Edit1.Text+'%'''; //Name_pinyin is one of the field of FDQuery1
      Filtered := True;
    end;
  end;
 
end;
 
end.

//FMX
object Form12: TForm12
  Left = 0
  Top = 0
  Caption = 'Form12'
  ClientHeight = 480
  ClientWidth = 640
  FormFactor.Width = 320
  FormFactor.Height = 480
  FormFactor.Devices = [Desktop]
  DesignerMasterStyle = 0
  object StringGrid1: TStringGrid
    Position.X = 32.000000000000000000
    Position.Y = 120.000000000000000000
    Size.Width = 577.000000000000000000
    Size.Height = 313.000000000000000000
    Size.PlatformDefault = False
    TabOrder = 4
    RowCount = 42
    RowHeight = 21.000000000000000000
  end
  object Button1: TButton
    Position.X = 464.000000000000000000
    Position.Y = 48.000000000000000000
    TabOrder = 9
    Text = 'Button1'
    OnClick = Button1Click
  end
  object Edit1: TEdit
    Touch.InteractiveGestures = [LongTap, DoubleTap]
    TabOrder = 10
    Position.X = 328.000000000000000000
    Position.Y = 8.000000000000000000
  end
  object FDConnection1: TFDConnection
    Params.Strings = (
      
        'Database=D:\Users\Public\Documents\Embarcadero\Studio\15.0\Sampl' +
        'es\Data\dbdemos.gdb'
      'User_Name=SYSDBA'
      'Password=masterkey'
      'DriverID=IB')
    Connected = True
    LoginPrompt = False
    Left = 96
    Top = 48
  end
  object FDQuery1: TFDQuery
    Active = True
    Connection = FDConnection1
    SQL.Strings = (
      'select * from employee')
    Left = 216
    Top = 48
  end
  object BindSourceDB1: TBindSourceDB
    DataSet = FDQuery1
    ScopeMappings = <>
    Left = 384
    Top = 48
  end
  object BindingsList1: TBindingsList
    Methods = <>
    OutputConverters = <>
    Left = 20
    Top = 5
    object LinkGridToDataSourceBindSourceDB1: TLinkGridToDataSource
      Category = 'Quick Bindings'
      DataSource = BindSourceDB1
      GridControl = StringGrid1
      Columns = <>
    end
  end
  object FDGUIxWaitCursor1: TFDGUIxWaitCursor
    Provider = 'FMX'
    Left = 528
    Top = 88
  end
end


--
Linden
"Mango" was Cool but "Wasabi" was Hotter but remember it's all in the "source"
George Wei

Posts: 40
Registered: 9/18/05
Re: No effect after set TDataSet's Filtered to true  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 18, 2015 4:50 PM   in response to: George Wei in response to: George Wei
I've tried TTMSFMXLiveGrid of TMS Pack for FireMonkey and TwwDataGrid of Woll2woll's FirePower 4.0 yesterday, both of them work fine. So I'm sure it's a bug of TStringGrid.

George
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02