简体   繁体   English

检查过滤字符串的TDataSet行

[英]Check at TDataSet row against a filter string

I am using a DevExpress TdxMemData in memory TDataSet descendant. 我在内存TDataSet后代使用DevExpress TdxMemData While it has Filtered: Boolean and Filter: String properties, it doesn't appear to actually do anything with them automatically, instead relying on the result of the OnFilterRecord event's Accept parameter. 虽然它具有Filtered:Boolean和Filter:String属性,但它似乎并不会自动对它们执行任何操作,而是依赖于OnFilterRecord事件的Accept参数的结果。

So what I am looking for is a way (maybe it is in TdxMemData or somewhere else in DevExpress's suite of code) to parse the filter text and apply it to the Dataset. 所以我正在寻找的方法(可能是在TdxMemData或DevExpress的代码套件中的其他地方)来解析过滤器文本并将其应用于数据集。

Ideally I would like a way to test an individual row against the filter to see if it matches without filtering it out of the dataset (I want to highlight rows that match the filter). 理想情况下,我想要一种方法来测试针对过滤器的单个行,以查看它是否匹配而不将其从数据集中过滤掉(我想要突出显示与过滤器匹配的行)。

Example filter string: 示例过滤字符串:

((Name = 'Jim') and (Rep > 1000)) or (Rep > 5000)

So there is nested and's and or's. 所以有嵌套和's和或。 It is actually built by the DevExpress TcxDBFilterControl. 它实际上是由DevExpress TcxDBFilterControl构建的。

I am really hoping there is something simple I am missing. 我真的希望有一些简单的我想念。

Update: I opened a ticket with DevExpress to see if they support any kind of solution. 更新:用DevExpress打开了一张票,看他们是否支持任何解决方案。 I did find their stock answer that they don't support filtering on TdxMemData. 我确实发现他们的股票回答他们不支持在TdxMemData上过滤。

I know this is not the answer your looking for, but the TdxMemData dataset does not support filter strings. 我知道这不是你要找的答案,但TdxMemData数据集不支持过滤字符串。 To use filters either code your own OnFilterRecord event or set ProgrammedFilter to true and populate the FilterList with a list of the records which are filtered (at runtime). 要使用过滤器,请编写自己的OnFilterRecord事件代码或将ProgrammedFilter设置为true,并使用已过滤的记录列表(在运行时)填充FilterList。

One possibility would be to code your own parser to compare the filter string against the current record in the OnFilterRecord event. 一种可能性是编写您自己的解析器,以将过滤器字符串与OnFilterRecord事件中的当前记录进行比较。

You might want to look at replacing the TdxMemData with TkbmMemTable . 您可能希望查看使用TkbmMemTable替换TdxMemData It's free, works similarly to the DX component, and supports filter strings. 它是免费的,与DX组件类似,并支持过滤字符串。 Would likely take a lot less time to port over than it would to implement a filter string parser in OnFilterRecord! 移植可能比在OnFilterRecord中实现过滤器字符串解析器要花费更少的时间! It'll work with the other DX components without problems. 它可以毫无问题地与其他DX组件一起使用。

What you're looking for is not filtering the data, but a matter of displaying it differently if it meets a condition. 您正在寻找的不是过滤数据,而是在满足条件时以不同方式显示数据。 If you're using a TDBGrid to display the data, look into the DrawColumnCell() event on the TDBGrid: 如果您使用TDBGrid显示数据,请查看TDBGrid上的DrawColumnCell()事件:

procedure TForm1.dbgrd1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
  DBG: TDBGrid;
begin
  DBG := TDBGrid(Sender);
  // Add any other conditions from your 'filter' here in the next line.
  if (YourData.FieldByName('WHATEVER').AsString = 'Jim') and
     (YourData.FieldByName('REP').AsInteger > 1000) then
    Column.Font.Color := clRed;
  DBG.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;

Since you're using TdxMemData, you're probably using the DevEx grid, too. 由于您使用的是TdxMemData,因此您可能也在使用DevEx网格。 It has to have a similar way to do something other than the default drawing; 它必须有类似的方法来做除默认绘图之外的其他事情; you can use a similar technique there. 你可以在那里使用类似的技术。 (I haven't used the DevEx stuff in a few years; current employer doesn't like them, and therefore won't spring for the expense. :-( ) (我几年没有使用DevEx的东西;现在的雇主不喜欢它们,因此不会花费费用。:-()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM