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