Board index » cppbuilder » Modifying TStringComponent

Modifying TStringComponent


2004-07-17 04:15:06 AM
cppbuilder99
I've scoured the newsgroup but haven't found anything similar to this,
so here's a question, that I'm hoping someone can help me with.
I have a TStringComponentNew that has as one of its features the ability
to resize the form on the fly so that it makes the cells fit magically
withing the viewable area of the grid (with no scrollbars or anyting of
that nature). To do this I simply fire off the WMSIZE event that I've
defined.
However I would like this event to also be fired off if the user changes
the number of columns or rows, but for the life of me I can't figure
out what I can do that...
Any ideas would be greatly appreciated...
John
 
 

Re:Modifying TStringComponent

John Theos <jtheos@cobasys_dot_com>wrote:
Quote
[...] However I would like this event to also be fired off
if the user changes the number of columns or rows,
I do understand what you're trying to accomplish but I don't
understand what your problem is. The user can't change the
number of columns or rows unless you provide them the means to
be able to do so. That's where you need to be adding code.
~ JD
 

Re:Modifying TStringComponent

JD wrote:
Quote
John Theos <jtheos@cobasys_dot_com>wrote:

>[...] However I would like this event to also be fired off
>if the user changes the number of columns or rows,


I do understand what you're trying to accomplish but I don't
understand what your problem is. The user can't change the
number of columns or rows unless you provide them the means to
be able to do so. That's where you need to be adding code.
JD,
thanks for the info. I was thinking that was the case, but I was
looking for a way to fire off the WM size event from the methods were
the cols/rows get modified. I think I was just having a serious block
on Friday...
Anyway, here's basically what I do now...let me know if you can think of
a better way, or if I'm simply brute forcing it.
I override the published properties ColCount and RowCount, and each gets
a new setter function.
The setter functions look like this:
//---------------------------------------------------------------------------
void __fastcall TAdvStringGrid::SetColCount(int Value)
{
//
FCols=Value;
TStringGrid::ColCount=Value;
if(this->Parent !=NULL)
{
ReSize.Width=Width;
ReSize.Height=Height;
Backup.Msg=0;
WMSize(ReSize);
}
}
//---------------------------------------------------------------------------
where ReSize is of type TWMSize.
 

{smallsort}

Re:Modifying TStringComponent

John Theos <jtheos@cobasys_dot_com>wrote:
Quote
[...] I override the published properties ColCount and
RowCount, and each gets a new setter function.
Not a bad idea.
Quote
The setter functions look like this:
<snip>
if(this->Parent !=NULL)
The only time the Parent would be NULL is during it's creation
or if you forgot to set it. Either way it's not needed - at
least not where you have it. *IF* you need to check the
Parent, it should be where you handle the WMSize event.
I would do something more like the following:
// add this to the header:
private:
typedef TStringGrid inherited;
//-------------------------------------------------------------
void __fastcall TAdvStringGrid::SetColCount(int Value)
{
inherited::ColCount = Value;
if( !ComponentState.Contains(csDesigning) )
{
FCols = Value;
::PostMessage( Handle, WM_SIZE, SIZE_RESTORED, MAKELPARAM(Width, Height) );
or
::SendMessage( Handle, WM_SIZE, SIZE_RESTORED, MAKELPARAM(Width, Height) );
}
}
//-------------------------------------------------------------
In the alternative, move the code from inside the message
handler into it's own function and call it directly from both
there and here.
~ JD