惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
G
Google Developers Blog
B
Blog
Engineering at Meta
Engineering at Meta
阮一峰的网络日志
阮一峰的网络日志
The Register - Security
The Register - Security
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 叶小钗
The Cloudflare Blog
The Hacker News
The Hacker News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
雷峰网
雷峰网
F
Fortinet All Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hackread – Cybersecurity News, Data Breaches, AI and More
酷 壳 – CoolShell
酷 壳 – CoolShell
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
A
About on SuperTechFans
量子位
Recorded Future
Recorded Future
博客园 - 三生石上(FineUI控件)
H
Help Net Security
Help Net Security
Help Net Security
P
Palo Alto Networks Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Troy Hunt's Blog
W
WeLiveSecurity
V
Vulnerabilities – Threatpost
T
The Exploit Database - CXSecurity.com
Know Your Adversary
Know Your Adversary
Apple Machine Learning Research
Apple Machine Learning Research
Scott Helme
Scott Helme
N
News | PayPal Newsroom
AWS News Blog
AWS News Blog
D
DataBreaches.Net
Blog — PlanetScale
Blog — PlanetScale
MongoDB | Blog
MongoDB | Blog
B
Blog RSS Feed
腾讯CDC
J
Java Code Geeks
Microsoft Azure Blog
Microsoft Azure Blog
TaoSecurity Blog
TaoSecurity Blog
GbyAI
GbyAI
Y
Y Combinator Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
D
Docker

博客园 - shappy

5.12默哀 台风 - shappy - 博客园 童谣 回家 Web Control中填写JavaScript报告"缺少对象"错误问题解决 Midas如何在服务器端自动产生流水号 Clientdataset关于record change by another user错误的总结 游凤凰 设定MSAgent的说话(Balloon)停留时间 获取Agent角色的动作列表 MSAgent简介 摘录 DelphiX简介 摘录 DelphiX的刷新 TList源码分析 摘录 几种文字编码的介绍 获取/打开/关闭输入法 汉字编码标准与识别 摘录 关于Tclientdataset的bug 队列类
Tclientdataset实现反向排序
shappy · 2007-05-14 · via 博客园 - shappy

ADO的sort可以很方便实现正向和方向排序,clt的排序可以用indexfieldnames,和indexDef.但是只支持正向排序.测试很长时间都没有办法利用这两个属性来实现反向排序,查看了clt的代码后,通过修改实现:

procedure TClientDataSet.SortOnFields(Cursor: IDSCursor; const Fields: string;
  CaseInsensitive, Descending: Boolean);
var
  I: Integer;
  FieldList: TList;
  DescFlags, CaseFlags: DSKEYBOOL;
  //shappy
  sFlds:string;

  function GetFlags(Flag: Bool; var FlagArray: DSKEYBOOL): Pointer;
  var
    J: Integer;
    //shappy
    s,s2:string;
    i:Integer;
  begin
{    if not Flag then Result := nil else
    begin
      for J := 0 to FieldList.Count - 1 do
        FlagArray[J] := True;
      Result := @FlagArray;
    end;}
    //shappy 修改成类似ado.sort的效果,可能存在bug,效率无优化
    if not Flag then begin
      s:= sFlds;
      i:=pos(';',s);  j:=0;
      while i>0 do begin
        if Copy(s,i-5,5)=' DESC' then
          FlagArray[j]:=True
        else
          FlagArray[j]:=False;
        inc(j);
        s:=copy(s,i+1,MaxInt);
        i:=pos(';',s);
      end;
      if (s<>'') and (Copy(s,Length(s)-4,5)=' DESC') then
        FlagArray[j]:=True
      else FlagArray[j]:=False;
    end else begin
      for J := 0 to FieldList.Count - 1 do
        FlagArray[J] := True;
      Result := @FlagArray;
    end;
  end;

begin
  FieldList := TList.Create;
  try
    //shappy
    sFlds:=UpperCase(Fields);
    GetFlags(Descending, DescFlags);
    i:=pos(' DESC',sFlds);
    while i>0 do begin
      sFlds:=Copy(sFlds,1,i-1)+copy(sFlds,i+5,MaxInt);
      i:=pos(' DESC',sFlds);
    end;
    GetFieldList(FieldList, sFlds);

    //GetFieldList(FieldList, Fields);
    for I := 0 to FieldList.Count - 1 do
      if TField(FieldList[I]).FieldNo > 0 then
        FieldList[I] := Pointer(TField(FieldList[I]).FieldNo) else
        DatabaseError(SFieldIndexError, Self);
      //shappy
      Check(Cursor.SortOnFields(FieldList.Count, PDWord(FieldList.List),
        @DescFlags, GetFlags(CaseInsensitive, CaseFlags)));
//    Check(Cursor.SortOnFields(FieldList.Count, PDWord(FieldList.List),
//      GetFlags(Descending, DescFlags), GetFlags(CaseInsensitive, CaseFlags)));
    GetIndexInfo('');
  finally
    FieldList.Free;
  end;
end;