在使用ClientDataSet作过滤时,发现它不支持中文,有解决的办法吗?(100分)

  • 主题发起人 主题发起人 程云
  • 开始时间 开始时间
这个问题我还未能解决,
现在换用Delphi7了,
用中文作为过滤是没问题了,
但用 like 作模糊过滤还是有问题。
这样是可以:
cdsMain.Filter := ' ssr like 三%' 。
这样就不成了:
cdsMain.Filter := ' ssr like %三' 。
这样也是不成:
cdsMain.Filter := ' ssr like %三%' 。
可能真是“Midas.dll”的问题,
还有一个叫“HyperBase”的东西,它是一个模拟“Midas.dll”的一个程序,
解决Delphi中所带“Midas.dll”的问题,
其中包含“DBClient.dll”“Midas.dll”。
也可试试LiChaoHui老兄说的那个,

这样就不成了:
cdsMain.Filter := ' ssr like %三' 。
这样也是不成:
cdsMain.Filter := ' ssr like %三%'
还不知如何解决。
 
to 程云兄:
过滤中,好像大多数都不支持你所说的那两种情况的,
模糊过滤也只支持以模式串开头的匹配方式,
你在Delphi7下面可以吗? 我的怎么不可以啊,
我的Midas.dll的日期是2002-8-9的,
无法对中文进行正确过滤,而我说的那个替代品是可以的,
不知道老兄是怎么做到的,教教我吧,拜托了
 
我喜歡這樣用
procedure Tform1.ClientDataSetFilterRecord(DataSet: TDataSet;
var Accept: Boolean);
begin
ClientDataset.filtered := false ;
Accept := ClientDataSet.fieldbyname('optype').asstring='购入'
ClientDataset.filtered := false ;
end;
 
to pengyi007:
当然关注了,我一直在盯着这个问题呢。
快请说一下,先谢过了。
 
to pengyi007:
服务端的自然是可以进行过滤的,
但这怎能最终来影响客户端。
用刷新吗?这是不成的。
能给个例子瞧瞧吗?
 
to pengyi007:
可以把你的方法说说吗?我也关注很久了。
 
服务器用filter
客户端用重新打开ClientDataset就可以
 
好~
ClientDataset当然不支持汉字过滤,我也试过好多次了
我已经解决,不知有没有人还在关注
我的邮箱是:pengyi007@tellyes.com
^-^
 
to pengyi007:
客户端的数据集关闭时,应用服务器上的相应数据集也关闭了。
 
我不太明白你的意思(客户端的数据集关闭时,应用服务器上的相应数据集也关闭了。 )
只需要服务器执行过滤操作后,客户端把数据集关闭后重新打开就可以了
 
to pengyi007:
我现在也是在服务器上fiter,但这样不太好,如果客户端查询太频繁,这样数据流量太大。TClientDataSet真的没法解决吗?
 
在多层分布式中,TClientDataSet不支持中文过滤,我是这样认为的
我用的方法完全可以满足我的需求,也没有再去研究
当然我也不知道别人是怎样解决的,甚至更好的解决方案!
 
给你个函数,这个可以用,我就用这个了
function ToCDSParamsString(s:string):string;
var
ws:WideString;
i:Integer;
begin
ws:=s;
for i:=1 to Length(ws)do
begin
if Ord(ws)>255 then
s:=s+'''';
end;
Result:=s;
end;
 
给你个函数,这个可以用,我就用这个了
function ToCDSParamsString(s:string):string;
var
ws:WideString;
i:Integer;
begin
ws:=s;
for i:=1 to Length(ws)do
begin
if Ord(ws)>255 then
s:=s+'''';
end;
Result:=s;
end;

真的就行了吗?
 
to freex07:
你到底有没有真正试过???!!!
 
ClientDataSet的过滤时,
支持 trim......等函数
 
// ClientDataSet1.Filter:='trim(optype)=''购入''';

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, Grids, DBGrids, DBClient, StdCtrls;
type
TForm1 = class(TForm)
ClientDataSet1: TClientDataSet;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
ClientDataSet1optype: TStringField;
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
ClientDataSet1.CreateDataSet;
ClientDataSet1.AppendRecord(['郝峰鸽']);
ClientDataSet1.AppendRecord(['购入']);
ClientDataSet1.AppendRecord([' 购入']);
ClientDataSet1.AppendRecord([' 购入 ']);
ClientDataSet1.AppendRecord([' 购入 ']);
ClientDataSet1.AppendRecord([' 购入']);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
ClientDataSet1.Filter:='optype=''购入''';
ClientDataSet1.Filtered:=true;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
ClientDataSet1.Filter:='trim(optype)=''购入''';
ClientDataSet1.Filtered:=true;
end;

end.


object Form1: TForm1
Left = 192
Top = 107
Width = 544
Height = 375
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object DBGrid1: TDBGrid
Left = 0
Top = 0
Width = 145
Height = 348
Align = alLeft
DataSource = DataSource1
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
end
object Button1: TButton
Left = 168
Top = 16
Width = 329
Height = 25
Caption = 'ClientDataSet1.Filter:=''optype=''''购入'''''';'
TabOrder = 1
OnClick = Button1Click
end
object Button2: TButton
Left = 168
Top = 48
Width = 329
Height = 25
Caption = ' ClientDataSet1.Filter:=''trim(optype)=''''购入'''''';'
TabOrder = 2
OnClick = Button2Click
end
object ClientDataSet1: TClientDataSet
Aggregates = <>
Params = <>
Left = 40
Top = 32
object ClientDataSet1optype: TStringField
FieldName = 'optype'
Size = 30
end
end
object DataSource1: TDataSource
DataSet = ClientDataSet1
Left = 104
Top = 88
end
end
 
//TStringField
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, Grids, DBGrids, DBClient, StdCtrls;
type
TForm1 = class(TForm)
ClientDataSet1: TClientDataSet;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
Button1: TButton;
Button2: TButton;
Button3: TButton;
ClientDataSet1optype: TStringField;
Button4: TButton;
Button5: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
ClientDataSet1.CreateDataSet;
ClientDataSet1.AppendRecord(['郝峰鸽']);
ClientDataSet1.AppendRecord(['购入']);
ClientDataSet1.AppendRecord([' 购入']);
ClientDataSet1.AppendRecord([' 购入 ']);
ClientDataSet1.AppendRecord([' 购入 ']);
ClientDataSet1.AppendRecord([' 购入']);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
ClientDataSet1.Filter:='optype=''购入''';
ClientDataSet1.Filtered:=true;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
ClientDataSet1.Filter:='trim(optype)=''购入''';
ClientDataSet1.Filtered:=true;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
ClientDataSet1.Filter:='optype like ''%购入%''';
ClientDataSet1.Filtered:=true;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
ClientDataSet1.Filter:='optype like ''购入%''';
ClientDataSet1.Filtered:=true;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
ClientDataSet1.Filter:='optype like ''%购入''';
ClientDataSet1.Filtered:=true;
end;

end.

object Form1: TForm1
Left = 192
Top = 107
Width = 544
Height = 375
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object DBGrid1: TDBGrid
Left = 0
Top = 0
Width = 145
Height = 348
Align = alLeft
DataSource = DataSource1
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
end
object Button1: TButton
Left = 168
Top = 16
Width = 329
Height = 25
Caption = 'ClientDataSet1.Filter:=''optype=''''购入'''''';'
TabOrder = 1
OnClick = Button1Click
end
object Button2: TButton
Left = 168
Top = 48
Width = 329
Height = 25
Caption = ' ClientDataSet1.Filter:=''trim(optype)=''''购入'''''';'
TabOrder = 2
OnClick = Button2Click
end
object Button3: TButton
Left = 168
Top = 80
Width = 329
Height = 25
Caption = ' ClientDataSet1.Filter:=''optype like ''''%购入%'''''';'
TabOrder = 3
OnClick = Button3Click
end
object Button4: TButton
Left = 168
Top = 112
Width = 329
Height = 25
Caption = ' ClientDataSet1.Filter:=''optype like ''''购入%'''''';'
TabOrder = 4
OnClick = Button4Click
end
object Button5: TButton
Left = 168
Top = 144
Width = 329
Height = 25
Caption = ' ClientDataSet1.Filter:=''optype like ''''%购入'''''';'
TabOrder = 5
OnClick = Button5Click
end
object ClientDataSet1: TClientDataSet
Aggregates = <>
Params = <>
Left = 40
Top = 32
object ClientDataSet1optype: TStringField
FieldName = 'optype'
Size = 30
end
end
object DataSource1: TDataSource
DataSet = ClientDataSet1
Left = 104
Top = 88
end
end
 
'ClientDataSet1.Filter:='optype='+#39+'购入'+#39
 
我也遇到过这个问题,但被我解决了,很简单的方法(用Socket),行好用的,速度还挺快的,不知大家还有没有关注此问题呀?
 
后退
顶部