关于TClientDataSet中文过滤问题(100分)

  • 主题发起人 主题发起人 MuMian
  • 开始时间 开始时间
M

MuMian

Unregistered / Unconfirmed
GUEST, unregistred user!
在一个三层结构里面,服务器端为SQL 2000,
需要在客户端对数据集 ClientDataSet1进行过滤,其中有一姓名字段(name),字段值为中文,表单中有一过滤条件编辑框 Edit1
当按如下语句执行成功:结果为所有数据集中姓李的数据ClientDataSet1.Filter :=’name like ’’’+’李%’+’’’’;
但当按下面的语句执行则无法实现过滤功能
ClientDataSet1.Fliter := ’name like ’’’+Edit1.Text+’%’+’’’’
此时在Edit1.Text = ’李’,但是无法过滤出符合条件的数据
请问哥哥们该如何解决
 
这样试试
ClientDataSet1.Fliter :='name like '''+Trim(Edit1.Text)+'%'+'''';
 
据我所知,TDataSet(Table,Quary,ClientDataSet)Fliter只能实现极其简单的过滤!
上序问题最好这样解决
procedure TForm1.ClientDataSet1FilterRecord(DataSet:TDataSet;varAccept:Boolean);
begin
Accept:=(Pos(Edit1.text,DataSet[name])>0);
end;
 
Table,Quary,的Filter 功能与ClientDataSet的Filter功能存在很大的区别,
应该说TClientDataSet的Filter功能是相当丰富的,能实现绝大多数的过滤要求,
我现在的问题是,在客户断需要根据诸多条件动态的进行过滤,
假如全部通过OnFilterRecord事件来实现的话,程序代码将回相当长
所以最好是通过TClientDataSet.Filter属性来进行,我想这应该是可能的
只是关于中文有这么一个问题:
当我用如下代码过滤成功
ClientDataSet1.Filter :='name like '''+'李%'+''''
但当我用下面的代码,则过滤不成功
ClientDataSet1.Filter :='name like '''+'%李%'+''''
这是不是因为中文的字节长度与其他字符号的字节长度不一样而导致原因而导致,
因为当我用下面的代码,则过滤成功
ClientDataSet1.Filter :='name like '''+'%Tom%'+''''
 
ClientDataSet(midas.dll)有很多Bug. 但其灵活性又无可替代, 真是让人哭笑不得.
我这里也有一个问题,在borland.public.datasnap上问竟无人应答,在网上查到有人
问过也无人回答:
With TClientDataSet, when using a filter - "fieldname like 'abcde'" where
the field "fieldname" is a widestring field, an error of "Type mismatched"
will occur.
Anybody solve the problem?
Nobody meets the same problem?
Here are just several simple steps to see the error:
1. Create a new application with default blank form, say Form1
2. Just drop a TClientDataSet on Form1, ClientDataSet1
3.do
uble click on ClientDataSet to add a new data Field, say field "a" with
data type of WideString and data length 10 (or any other number)
4. Close the Fields Editor
5. Right click on ClientDataSet1 and select "Create Dataset" from the pop up
menu
6. (Now the ClientDataSet1 is Active)
7.do
uble click the Filtered property value(should be false now) on Object
Inspector, i.e. Filtered := True;
8. Set the Filter property to: a = '123', OK, no problem
9. Try another string: a like '123', ERROR!!! Message: "Type mismatch in
expression"
Would it be a BUG?
Anybody encounters the same problem?
 
有同感,NeutronDelphi所言不失为一个解决办法.
类似问题可参阅:
http://www.csdn.net/expert/topic/885/885041.xml?temp=.6753351
 
其实这是由于文字编码的问题,听过UniCode吗?
搜索一下吧,我记得以前我看过相关的帖子,^_^
 
多人接受答案了。
 
后退
顶部