myLocate 加強 Locate 功能

有關Delphi 的語法, 程式, 等
回覆文章
頭像
tim
文章: 1380
註冊時間: 2008年 11月 26日, 00:49

myLocate 加強 Locate 功能

文章 tim »

myLocate 加強 Locate 功能, 但速度比較慢

自己寫的 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; 
多多留言, 整理文章, 把經驗累積下來.....
回覆文章