我想要点击一个BUTTON判断stringgrid中某列是否有重复值,这个算法怎么写?我下面的代码不对,不知错在哪里了?
var i,j :integer;
var str1,str2:string;
begin
  for i:=1 to stringgrid1.RowCount-1 do
    str1:=stringgrid1.Cells[1,i];
     for j:=i+1 to stringgrid1.RowCount-1 do
      begin
         str2:=stringgrid1.Cells[1,j];
         if str1=str2 then
         begin
             application.MessageBox('重复','提示',64);
             exit;
         end;
      end;end;

解决方案 »

  1.   

    for i:=1 to stringgrid1.RowCount-1 do
    后面少了对
    begin...end
      

  2.   

    var 
      i,j :integer; 
      str1,str2:string; 
    begin 
      for i:=1 to stringgrid1.RowCount-1 do 
      begin
        str1:=stringgrid1.Cells[1,i]; 
        for j:=i+1 to stringgrid1.RowCount-1 do 
        begin 
          str2:=stringgrid1.Cells[1,j]; 
          if str1=str2 then 
          begin 
            application.MessageBox('重复','提示',64); 
            exit; 
          end; 
        end; 
      end;
    end;