Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-12

TStringGrid: ColCount vs Columns.Count

7 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Alexander Klenin

Currently, ColCount and Column.Count values of TStringGrid are independent, which leads to user errors and confusion.
It also necessitates many "C nil" checks throughout the TStringGrid code. I propose to implement auto-creation of TGridColimns upon every change of ColCount, which should eliminate both problems. Is it a good idea? Should I enter it into a tracker?

Alexander S. Klenin Insight Experts Ltd.

Reply by email

Jesus Reyes
to Alexander Klenin

--- El lun 8-dic-08, Alexander Klenin escribi?:

Show quoted text 17 lines
De:: Alexander Klenin Asunto: [Lazarus] TStringGrid: ColCount vs Columns.Count A: "General mailing list" Fecha: lunes, 8 diciembre, 2008, 6:49 pm Currently, ColCount and Column.Count values of TStringGrid are independent, which leads to user errors and confusion. It also necessitates many "C nil" checks throughout the TStringGrid code. I propose to implement auto-creation of TGridColimns upon every change of ColCount, which should eliminate both problems. Is it a good idea? Should I enter it into a tracker? -- Alexander S. Klenin Insight Experts Ltd.

Indeed it worked that way when custom columns (cc) were implemented, what I didn't like is that it may "cancel" cc without notice, for example when at design time a set of cc are set up and this is why it currently enforce the use of cc to change counts.

But I don't really see a problem that colcount changes automatically the number of cc if there are some already, if there are no cc I think it should not add any, or what you think about it?

Jesus Reyes A.

?Todo sobre Amor y Sexo!
La gu?a completa para tu vida en Mujer de Hoy.
http://mx.mujer.yahoo.com/

Reply by email

Alexander Klenin
to Jesus Reyes
Jesus Reyes wrote
Indeed it worked that way when custom columns (cc) were implemented, what I didn't like is that it may "cancel" cc without notice, for example when at design time a set of cc are set up and this is why it currently enforce the use of cc to change counts. But I don't really see a problem that colcount changes automatically the number of cc if there are some already, if there are no cc I think it should not add any, or what you think about it?

The problem I ran into was as follows:

SGrid.ColCount := 2;
SGrid.Columns[1].Alignment := taCenter; // Oops!

It is counter intuitive to me that the above code needs additional call to SGrid.Columns.Add

So, IMO the correct solution would be to _remove_ SGrid.Columns.Add totally and add/remove columns as needed when ColCount changes, thus leaving a single well-defined interface without the possibility of confusion.

However, this is not backwards-compatible... so, as a compromise, perhaps Columns.Add should increase ColCount to keep both in sync?

Alexander S. Klenin Insight Experts Ltd.

Reply by email

Jesus Reyes

--- El mar 9-dic-08, Alexander Klenin escribi?:

Show quoted text 20 lines
De:: Alexander Klenin Asunto: Re: [Lazarus] TStringGrid: ColCount vs Columns.Count A: Fecha: martes, 9 diciembre, 2008, 1:10 pm On Wed, Dec 10, 2008 at 03:41, Jesus Reyes wrote: > --- El mar 9-dic-08, Alexander Klenin escribi?: >> It is counter intuitive to me that the above code needs additional >> call to SGrid.Columns.Add > > This seems to suggest that grid should always use custom columns, but no all applications require them. Sure, but what is the downside of always having them? Slightly increased memory consumption? If memory truly is a problem, it can be mitigated by creating custom columns lazily (i.e. on demand).

[snip]

Show quoted text 5 lines
> > what about fixed columns? should indices also count them? Of course. Does not they now?

no they don't.

I think you wasn't too clear on what is what you wanted, anyway I think it has nothing wrong with having custom columns even for fixed cols, just it was not the initial goal.

Show quoted text 13 lines
>if there are two fixed columns what column should Sgrid.Columns[1] refer to?. To the second of them. >> However, this is not backwards-compatible... so, as a compromise, >> perhaps Columns.Add should increase ColCount to keep both in sync? > > This can be done, but I don't think all problems of intutiveness(?) will disappear for all cases. What problems do you think will be left unsolved?

Many if you think in the current situation and just changing SetColCount to get custom columns and columns on sync, but now I understand what you want, it would be nice indeed.

As I think it's not just changing a couple of lines, I would like to know what other persons think about this feature, would it be welcomed no not? if there is enough demand we can do it.

-- Alexander S. Klenin Insight Experts Ltd.

Jesus Reyes A.

?Todo sobre Amor y Sexo!
La gu?a completa para tu vida en Mujer de Hoy.
http://mx.mujer.yahoo.com/

Reply by email

Alexander Klenin
to Jesus Reyes
> > what about fixed columns? should indices also count them? > Of course. Does not they now? no they don't.

Hm. So currently it is impossible to have, say, right-aligned text in fixed column?
I'd say it is a bug.

I think you wasn't too clear on what is what you wanted, anyway I think it has nothing wrong with having custom columns even for fixed cols, just it was not the initial goal.

Yes, I did not fully understand that my self at first ;-)

[snip]

Many if you think in the current situation and just changing SetColCount to get custom columns and columns on sync, but now I understand what you want, it would be nice indeed.

I agree.

Alexander S. Klenin Insight Experts Ltd.

Reply by email

Jesus Reyes
to Alexander Klenin

--- El mar 9-dic-08, Alexander Klenin escribi?:

Show quoted text 10 lines
>> > what about fixed columns? should indices also count them? >> Of course. Does not they now? > no they don't. Hm. So currently it is impossible to have, say, right-aligned text in fixed column? I'd say it is a bug.

Using custom columns it is impossible because they were introduced by "back porting" dbgrid columns to standard grid, and you don't have a custom column for indicator column. So in my view it's not a bug but a feature :)

Of course you can have a right aligned fixed column, using OnPrepareCanvas just need to check when a fixed col is being "prepared" and set canvas.textstyle to the alignment you want. Yes it's not the same as with custom columns but at least it's not impossible :)

Jesus Reyes A.

?Todo sobre Amor y Sexo!
La gu?a completa para tu vida en Mujer de Hoy.
http://mx.mujer.yahoo.com/

Reply by email

Jesus Reyes
to Jesus Reyes: --- El mar 9-dic-08, Alexander Klenin escribi?: [snip] no they don't. I think you wasn't…

--- El mar 9-dic-08, Jesus Reyes escribi?:

Show quoted text 6 lines
As I think it's not just changing a couple of lines, I would like to know what other persons think about this feature, would it be welcomed no not? if there is enough demand we can do it.

after that overwhelming demand (or the lack of it) I think we should try to make custom columns available by default, please submit a bug report asking for the feature I will be looking to implement it before 1.0.

Jesus Reyes A.

?Todo sobre Amor y Sexo!
La gu?a completa para tu vida en Mujer de Hoy.
http://mx.mujer.yahoo.com/

Reply by email