zoukankan      html  css  js  c++  java
  • TClientDataSet[14]: 测试 FindFirst、FindNext、FindLast、FindPrior、Found


    //先在窗体添加 ClientDataSet1 和两个 Button
    
    { 初始化测试数据 }
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      with ClientDataSet1 do begin
        FieldDefs.Add('ID', ftInteger);
        FieldDefs.Add('Name', ftString, 6);
        FieldDefs.Add('Age', ftWord);
        CreateDataSet;
        AppendRecord([1, 'A',    11]);
        AppendRecord([2, 'AB',   22]);
        AppendRecord([3, 'ABC',  33]);
        AppendRecord([4, 'ABCD', 44]);
        AppendRecord([5, 'a',    55]);
        AppendRecord([6, 'ab',   66]);
        AppendRecord([7, 'abc',  77]);
        AppendRecord([8, 'abcd', 88]);
      end;
    end;
    
    { FindFirst、FindNext、FindLast、FindPrior }
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      ClientDataSet1.Filter := 'Name Like ''%c%''';
      ClientDataSet1.FilterOptions := [foCaseInsensitive];
      ClientDataSet1.Filtered := True;
    
      if ClientDataSet1.FindFirst then ShowMessage(ClientDataSet1['Name']); { ABC }
      if ClientDataSet1.FindNext then ShowMessage(ClientDataSet1['Name']);  { ABCD }
      if ClientDataSet1.FindLast then ShowMessage(ClientDataSet1['Name']);  { abcd }
      if ClientDataSet1.FindPrior then ShowMessage(ClientDataSet1['Name']); { abc }
    
      ClientDataSet1.Filtered := False;
    end;
    
    { 遍历过滤结果 }
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      ClientDataSet1.Filter := 'Name Like ''%c%''';
      ClientDataSet1.FilterOptions := [foCaseInsensitive];
      ClientDataSet1.Filtered := True;
    
      ClientDataSet1.FindFirst;
      while ClientDataSet1.Found do
      begin
        ShowMessage(ClientDataSet1['Name']); { ABC / ABCD / abc / abcd}
        ClientDataSet1.FindNext;
      end;
    
      ClientDataSet1.Filtered := False;
    end;
    
  • 相关阅读:
    Win2003 远程控制管理工具tsmmc 移植到XP连接多个服务器远程桌面的方法
    c++中new char(10) 和 new char[10]的区别
    64位ubuntu上安装 hadoop2.4.0
    g++编译安装
    atoi()函数实现
    LRU Cache
    Longest Palindromic Substring
    Java 中 == 和 equal 的区别 (String)
    抓取HTML
    验证码居中
  • 原文地址:https://www.cnblogs.com/del/p/1662699.html
Copyright © 2011-2022 走看看