If StringGrid1.cells[i,j]='1' then (чётность столбцов) inc(bufferCell); If StringGrid1.cells[j,i]='1' then (чётность строк) inc(bufferStr);