程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> TClientDataSet[14]: 測試 FindFirst、FindNext、FindLast、FindPrior、Found

TClientDataSet[14]: 測試 FindFirst、FindNext、FindLast、FindPrior、Found

編輯:Delphi

//先在窗體添加 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; 


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved