就是cxgrid里一列数据,从数字1 .2.3.4.5....100到100吧,能查找出中间丢了哪个数了。

解决方案 »

  1.   

    var
      CheckNum:array [1..100] of Byte;  iRow,I: Integer;
    begin
      fillchar(CheckNum,sizeof(CheckNum),0);
      for iRow := 0 to cxgrid.RowCount - 1 do begin
        CheckNum[StrToInt(cxgrid.Cells[ACol(*相应的列*), iRow])] := 1;
      end;  for i := 1 to 100 begin
        if CheckNum[i] = 0 then ShowMessage(format('缺少:%d',[i]));
      end;
    end;
      

  2.   


    1.先把Query按序号排序
    2.以Query的记录数为最大连续号进行循环,假如有100条记录
    For i:=1 to Query.RecordCount do
    begin
      if Query.FieldByName('ID').AsInteger<>I then
      begin
        //记录断号
      end;
      Query.Next;
    end;
      

  3.   


     //定义一个数组:
     Var
     InArray: Array[1..100] of Boolean; for I:=0 to cxGrid.cxGridTableView1.DataController.RecordCount do
        InArray[cxGrid.cxGridTableView1.DataController.Values[I,1]]:=True; //第一列的值,这里没有判断是否在[1..100]之间,实际上要判断,否则有时会数组越界错误
      for I:=1 to 100 do
      if not InArray[I] then
        showmessage(format('%d',[I])); //不在范围内的数
      

  4.   

    此问题,若是从库中来读取的话,结合delphi,如何写呢?速度又会是如何的呢?多谢了。
      

  5.   


    declare   @i   int   
      select   @i=max(id)   from   yourtable   
      exec('select   top   '+@i+'   id=identity(int,1,1)   into   tmp   from   syscolumns   a,syscolumns   b')   
        
      select   t.id   
      from   tmp   t   
      where   not   exists(select   1   from   yourtable   where   id=t.id)  
     
      

  6.   

    MS SQL Server
    select 1 from tablename a(nolock) 
    where cast(fieldname as int)<>100 
      and not exists(
                     select 1 from tablename (nolock)
                     where cast(fieldname as int) = cast(a.fieldname as int) + 1
                    )
      

  7.   

    select cast(fieldname as int)+1 as fieldname from tablename a(nolock) 
    where cast(fieldname as int)<>100 
      and not exists(
                     select 1 from tablename (nolock)
                     where cast(fieldname as int) = cast(a.fieldname as int) + 1
                    )
      

  8.   

    一般cxGrid都有一个view
    假设这个view是viewA,在viewA中需要处理的列名为viewAFieldA
    viewA有个DataController属性
    代码大致可以这样写
    var
      I:integer;
    with viewA.DataController do
    begin
      first;
      while not EOF do
      begin
      for I := 1 to 100 do
        begin  
          if I = viewAFieldA.databanding.field.asinteger then 
           continue
          else
          //保存这个I
        end;
      next;
      end; 
    end
    手写代码,仅供参考.
    如有问题,欢迎加QQ讨论(敲门CSDN cxGrid)