Board index » cppbuilder » Re: Subclass TStringGrid with two new properties

Re: Subclass TStringGrid with two new properties


2006-02-02 07:06:24 PM
cppbuilder8
JD,
Thanks again, I have added the properties for changing
rows and for changing cols... It works perfectly.
Last problem that I have is that when I create new
MyObject instances for Cells then for the Font and Color
variable I'm using the Grid's Font/Color values:
Cell *zelle = new Cell;
zelle->Font->Color = Font->Color; // Grid->Font->Color
zelle->Font->Height = Font->Height; // Grid->Font->Height
zelle->Font->Style = Font->Style; // and so on...
zelle->Font->Name = Font->Name;
zelle->Color = Color;
Objects[spalte][zeile] = reinterpret_cast<TObject*>(zelle);
This works great apart of one exception...
The constructor of the grid creates 5 rows and 5 cols by
default. At this point my Font and Color values for the grid
are not set yet.
My workaround is that I delete all cells with:
MyRowCount = 0;
set the font and color values of the grid
and then set MyRowCount again so that all cells are
filled with the right Font/Color values.
My question is, have you another idea or is it possible to
overwrite grid's constructor for creation of 0 rows and 0
cols?
Thanks for your time
Marius
 
 

Re:Re: Subclass TStringGrid with two new properties

"mauro" < XXXX@XXXXX.COM >wrote:
Quote

[...] This works great apart of one exception...
The constructor of the grid creates 5 rows and 5 cols by
default. At this point my Font and Color values for the grid
are not set yet.
I don't understand what the problem is because if you add code
to the grid's ctor, you'll see that they are indeed set. I'm
thinking that you mean that you haven't set the Color ect. yet
after you have allocated it from within the Parent form.
Quote
My workaround is that I delete all cells with:
If, when you have completed your grid's code, you install it
into the IDE as a component, this will not be an issue because
the Color specified in the Object Inspector will be valid when
you code executes. For now, you have a couple of choices. One
is to explicitly set the Color in the grid's ctor. Another is
to add a MyColor property and setter method that will itterate
existing Objects and change the Color of TMyObject. However, a
public function might be better because you can pass in
multiple parameters.
Another option is to use a custom message that you post to the
grid's handle from within the grid's ctor. That message won't
get processed until every thing has finished constructing
(including the form's ctor where you allocated the grid)
which means that your Color will be set by that time.
~ JD