views:

63

answers:

2

I've got a form with a DB grid on it. It worked fine as a normal TDBGrid, but when I replaced it with the Scalabium TSMDBGrid, I started getting exceptions while loading the form.

Here's the problem, as far as I can track it down:

While loading the columns from the DFM, it attempts to set the Expanded property on the first column to False. This is set in the Form Designer, and can't be changed unless the column is bound to a field representing an ADT or array.

For some reason, the columns are created in the constructor with FExpanded set to true. When the reader reaches this point, it calls TColumn.SetExpanded(false), which does this:

begin
  if Value <> FExpanded then
  begin
    Grid := GetGrid;
    WasShowing := (Grid <> nil) and Grid.Columns[Grid.SelectedIndex].Showing;
    ...

Unfortunately, at this point Grid.SelectedIndex is -1, so I get "Exception class EListError with message 'List index out of bounds (-1)'." This is a pretty clear invariant: SelectedIndex should not be -1 when SetExpanded is called. Does anyone know why the TSMDBGrid is breaking it and what I can do to fix it?

A: 

I would try assigning the dataset/datasource properties in code, instead of designtime, just as a quick work around.

Warren P
Nope. I tried leaving the DataSource property unassigned, and it didn't change anything.
Mason Wheeler
A: 

Try to recreate the column list if designer

Mike Shkolnik
I tried that. Multiple times, in fact. It didn't help.
Mason Wheeler