现有两个字段client 字符型,htflag 布尔型
如果client有相同的记录那么htflag自动打钩

解决方案 »

  1.   

    思路大概这样:先循环找到client值相同的记录起来(可以放到数组中,也可以放到TStringList里面),然后再走循环对htflag打勾。
      

  2.   

    for i := 0 to lstClient.count - 1 do
    begin
     if not lsthtflag[i] then
     beging
      for j:=i to lstClient.Count - 1 do
      begin
        if lstClient[i]=lstClient[j] then
        begin
          lsthtflag[i]:= true;
          lsthtflag[j]:= true;
          break;
        end;
      end;
    end;
    end;
      

  3.   

    1、将需要处理的数据读入DBGrid1中;
    2、执行以下代码:
    procedure TMedicineInOutFrm.Button45Click(Sender: TObject);
    var S:string;
        A:array of array [0..1] of String;
        Top,I,J:integer;
        T:boolean;
    begin
      with DBGrid1.DataSource.DataSet do
      begin
        First;
        Top:=0;
        while Not Eof do
        begin
          S:=FieldByName('client').asString;
          if S<>'' then
          begin
            SetLength (A, Top+1);
            A[Top,0]:=S;
            Top:=Top+1;
          end;
          Next;
        end;
      end;
      for I:=0 to Top-1 do
        for j:=0 to Top-1 do
          if I<>j then
            if A[i,0]=A[j,0] then A[i,1]:='1';
      with DBGrid1.DataSource.DataSet do
      begin
        First;
        while Not Eof do
        begin
          T:=False;
          S:=FieldByName('client').asString;
          for I:=0 to Top-1 do
            if A[i,0]=S then
              if A[i,1]='1'  then T:=True;
          Edit;
          FieldByName('htflag').asBoolean:=T;
          Post;
          Next;
        end;
      end;
    end;