各位前辈,我发现ClientDataSet.Locate 关于 bit字段不能定位,比如用ClientDataSet.Locate('查看',(1),[])或者用ClientDataSet.Locate('查看',(true),[])都没法定位到我要的数据,请各位高手帮忙!小弟感激不尽!

解决方案 »

  1.   

    Locate('查看'', vararrayof([1]), []); 
      

  2.   

    function Locate(const KeyFields: string; const KeyValues: Variant; Options: TLocateOptions): Boolean; override;
    你的“查看”字段必须具有唯一性才可以,否则无法定位。
      

  3.   

    早就发现这个问题了,最好不要使用BIT了,用整数代替吧
      

  4.   

    你找一个key不久可以了。locate支持多个字段联合定位。
    贴一段delphi的描述及示例:
    Call Locate to search a dataset for a specific row and make it the current row.KeyFields is a string containing a semicolon-delimited list of field names on which to search.KeyValues is a variant that specifies the values to match in the key fields. If KeyFields lists a single field, KeyValues specifies the value for that field on the desired row. To specify multiple search values, pass a variant array as KeyValues, or construct a variant array on the fly using the VarArrayOf routine. For example:with ADOTable1 do
      Locate('Company;Contact;Phone', VarArrayOf(['Sight Diver', 'P', '408-431-1000']), [loPartialKey]);
      

  5.   

    顶楼上的啊!
    楼主有时间,应该多跟踪跟踪Delphi源代码
      

  6.   

    不是啊,我一定要定位那个bit字段,不然我也不用到这边求助啦!
      

  7.   

    如果有20条记录,请告诉计算机如何才能根据bit来定位?如果不能就做不了。
    就好比有10棵白菜(10棵带都带,或者是一部分带,一部分不带),你要那棵带根的。请问你要选择哪棵?
    有的时候,你不必局限非得要某种方法来达到,你可以把问题放大,换一种方法,思路。
    达到你要的目的!
      

  8.   

    Locate有多条符合条件的数据一般都是定位第一条啊!