自己寫的 Locate , 可以續找, 但只支援單一欄位及參數, 並多增加了一個 checkCurrent 的參數, 目地是否要比對該 dataset 的目前這筆資料.
代碼: 選擇全部
function myLocate(dataset: TDataSet; const KeyFields: String; const Keyvalues: String; Options: TLocateOptions;
checkCurrent: Boolean = true): Boolean;
var
cur: TBookMark;
oristr, compstr: string;
begin
cur := dataset.GetBookmark ;
Result := false;
if not checkCurrent then dataset.Next;
while not dataset.Eof do
begin
if loCaseInsensitive in Options then
begin
oristr := UpperCase(dataset.FieldByName(KeyFields).AsString);
compstr := UpperCase(Keyvalues);
end
else
begin
oristr := dataset.FieldByName(KeyFields).AsString;
compstr := Keyvalues;
end;
if loPartialKey in Options then
begin
if Copy(oristr, 1, length(compstr)) = compstr then
begin
Result := true;
break;
end;
end
else
begin
if oristr = compstr then
begin
Result := true;
break;
end;
end;
end;
if Result = false then
dataset.GotoBookmark(cur);
end;