Recent

Author Topic: TBufDataset Filter by Field that has a space in the field name.  (Read 2820 times)

dmitryb

  • Jr. Member
  • **
  • Posts: 50
Hi All

How to assign Filter property of the TBufDataset if a field has a space in the name?

Code: Pascal  [Select][+][-]
  1.   BufDataset2.Filter := 'FieldName WithSpace = ''Value1''';
  2.   BufDataset2.Filter := '[FieldName WithSpace] = ''Value1''';

does not work.

Here is a Test code:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button3Click(Sender: TObject);
  2. var
  3.   BufDataset2: TBufDataset;
  4. begin
  5.   BufDataset2 := TBufDataset.Create(nil);
  6.  
  7.   BufDataset2.FieldDefs.Add('FieldName WithSpace', ftString, 200);
  8.   BufDataset2.CreateDataset;
  9.   BufDataset2.AppendRecord(['Value1']);
  10.   BufDataset2.AppendRecord(['Value2']);
  11.   BufDataset2.Filter := 'FieldName WithSpace = ''Value1''';
  12.   //BufDataset2.Filter := '[FieldName WithSpace] = ''Value1''';
  13.   BufDataset2.Filtered := True;
  14. end;
  15.  





kjteng

  • Full Member
  • ***
  • Posts: 208
Re: TBufDataset Filter by Field that has a space in the field name.
« Reply #1 on: October 28, 2021, 12:49:19 pm »
I think the parser cannot handle field name containing spaces.
However,  you can do the filtering via DoFilterRecord event. Something like this:

procedure TForm1.xxFilterRecord(DataSet: TDataSet; var Accept: Boolean);
begin
   accept := dataset.Fieldbyname('FieldName WithSpace').AsString ='Value1';
end;       


 

TinyPortal © 2005-2018