Subject RE: [IBO]Desperate for D6 Help - DynamicGrid
Author Paul Hope
Hi Geoff

> > I had made a change to TIB_Grid which looked innocent enough but
> > removing it removed the problem.
>
> No change to the grid is innocent... just ask Jason. I doubt
> if there is any visual control in the system that has caused
> as much trouble as the grid.
>
Oh yes - that I already know ;-)

That is part of the reason I was creating a derivitive of IB_Grid instead of
making changes to it. I know I still have to manage some difficult areas
but at least there is minimal code disruption to the grid.

I have now solved the problem that was causing D6 to access violate. I
moved the OnGetRowHeight event to the derivitive (where it should have been
anyway) so - apart from making a few things virtual so I could override them
all I have had to do to IB_CustomGrid is add a protected virtual function
GetRowHeight and add a few lines of code to DrawCell.

>
> > I am attempting to create a derivitive of TIB_Grid which
> changes the
> > height of each row according to the amount of text in a memo field
> > obtained via an OnGetRowHeight event.
> [...]
> > The above is all it needs to access violate when placed on
> a form, I
> > call it in DrawCell but it violates without that code.
>
> > Any idea why this doesn't work?
>
> Because drawing the grid is not the only place the row height
> is used. Take a look, for example, at the VisibleGridRows
> function and the places that is called from.
>

I know - but it still works. One of the places is DefaultDrawCell which I
havent figured out the purpose of yet. I override VisibleGridRows because
its central to what I'm doing.

> There is a RowHeights[Index: Longint] property in TCustomGrid
> that you could use in your derivative. (Jason does not make
> the property public in TIB_CustomGrid because he does not
> support variable height rows... you are discovering why not.)
>
I set RowHeights[ARow] in DrawCell so I might be overriding some other
behavior (something to do with ScalingFlags?)

> I suggest you do NOT try to change a rowheight while drawing,
> as I expect that a change in rowheight will generate an
> invalidate or repaint. You could try doing it in response to
> the OnTopLeftChanged event (as the grid scrolls you alter the
> rowheights... I think that makes sense but have not played
> with it myself).
>
> You will run into other problems (scrollbar sync etc etc).
> But if you have the time to spend on it... and you will need
> lots of time because no change to the grid is innocent or
> simple; variable height rows least of all.
>
> (If you work out how to do it then I imagine Jason may be
> interested in seeing the result.)

Changing RowHeights(ARow] in DrawCell does actually work and doesnt cause
any problems with scrollbars etc. Presumably by luck I change it in time.
OnTopLeftChanged might be a good idea but I would still have to cope with
displaying rows when it isnt changed (eg first display or data has changed
which requires row resizing).

I have had some discussion with Jason about it and we thought the way to go
would be to add a RowHeight property to the data buffer row object via an
OnGetRowHeight event. In the meantime I am accessing the OnGetRowHeight
event very heavily as opposed to just reading a value.

Subject to some small quirks and a few things I havent completed (like page
up via the scroll bar) I have got it working in a production environment
where the use is limited.

I shall plod on and see where I get to - thanks for your help

Regards
Paul