Forum > Database

TBufDataset Filter by Field that has a space in the field name.

(1/1)

dmitryb:
Hi All

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


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  BufDataset2.Filter := 'FieldName WithSpace = ''Value1''';  BufDataset2.Filter := '[FieldName WithSpace] = ''Value1''';
does not work.

Here is a Test code:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button3Click(Sender: TObject);var  BufDataset2: TBufDataset;begin  BufDataset2 := TBufDataset.Create(nil);   BufDataset2.FieldDefs.Add('FieldName WithSpace', ftString, 200);  BufDataset2.CreateDataset;  BufDataset2.AppendRecord(['Value1']);  BufDataset2.AppendRecord(['Value2']);  BufDataset2.Filter := 'FieldName WithSpace = ''Value1''';  //BufDataset2.Filter := '[FieldName WithSpace] = ''Value1''';  BufDataset2.Filtered := True;end; 



kjteng:
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;       

Navigation

[0] Message Index

Go to full version