Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Compare Cells

bubblybubbly Member Posts: 18
[b][red]This message was edited by bubbly at 2005-4-13 4:25:58[/red][/b][hr]
The user populates a TstringGrid, and when they click save I want to check every cell in column 1 to make sure none of them are the same (column 1 holds the primary key). The number of rows is set to 50 (for other reasons).

I have tried so many loops etc and I still can't get it to work. I've just been looking at it so long I can't see any problem and can't see a different way out of it.

Any suggestions?


Comments

  • zibadianzibadian Member Posts: 6,349
    : [b][red]This message was edited by bubbly at 2005-4-13 4:25:58[/red][/b][hr]
    : The user populates a TstringGrid, and when they click save I want to check every cell in column 1 to make sure none of them are the same (column 1 holds the primary key). The number of rows is set to 50 (for other reasons).
    :
    : I have tried so many loops etc and I still can't get it to work. I've just been looking at it so long I can't see any problem and can't see a different way out of it.
    :
    : Any suggestions?
    :
    :
    :
    Here is a short working code:
    [code]
    AllUniqueStrings := true; // Assume all strings are unique
    for i := 0 to RowCount-2 do
    for j := i+1 to RowCount-1 do // Loop across cells lower than row i
    if [blue]Cells[0, j] = Cells[0, i][/blue] then
    begin
    AllUniqueStrings := false; // A match has been found
    Break; // Shorten loop, because already found a match
    end;
    [/code]
    I've left out the references to the grid to make the code more readable. If you want to check if the strings are unique without case-sensitifity, you should change the blue part into:
    [code]
    CompareText(Cell[0,j], Cell[0, i]) = 0
    [/code]
Sign In or Register to comment.