Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad Assert in TVirtualTreeColumns.GetPreviousColumn #1235

Open
tecmatia-dp opened this issue Jan 16, 2024 · 0 comments
Open

Bad Assert in TVirtualTreeColumns.GetPreviousColumn #1235

tecmatia-dp opened this issue Jan 16, 2024 · 0 comments

Comments

@tecmatia-dp
Copy link

I recently updated to V8.0.
In a tree with 45 columns, which allow the user to change the order, I am seeing an exception in some cases, with the error "The previous column must not have the same position as the given column."
Debugging the problem, I locate the origin in the function TVirtualTreeColumns.GetPreviousColumn:

function TVirtualTreeColumns.GetPreviousColumn(Column : TColumnIndex) : TColumnIndex;

// Returns the previous column in display order, Column is an index into the columns list.

var
  Position : Integer;

begin
  if Column < 0 then
    Result := InvalidColumn
  else
  begin
    Position := Items[Column].Position;
    if Position > 0 then
      Result := FPositionToIndex[Position - 1]
    else
      Result := InvalidColumn;
    Assert(Position <> Result, 'The previous column must not have the same position as the given column.');
  end;
end;

With this array of positions:
FPositionToIndex = (0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 9, 43, 44, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35, 36, 37, 38, 39, 40, 31, 42, 45, 41)
Without any repeated value, it throws the assert exception, for Column=41, and Position=45, but it should not.

I have realized that the Assert is comparing an index with a position, ... the correct thing would be

Assert(Result <> Column, 'The previous column must not have the same position as the given column.');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant