BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

OnDrawCell (TStringGrid) requesting constant TRect

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development)
View previous topic :: View next topic  
Author Message
Erik Doekes
Guest





PostPosted: Sun Jul 03, 2005 11:34 am    Post subject: OnDrawCell (TStringGrid) requesting constant TRect Reply with quote



Hi!

In the help to C++Builder Personal it is stated that the OnDrawCell event
has parameters
(TObject*, long, long, TRect, TGridDrawState)
but when try to run an application with a grid derived from TStringGrid
containing an OnDrawCell event it seems that the compiler wants
(TObject*, int, int, const TRect &, TGridDrawState)
as parameters.

Changing long to int doesn't bother me, since I will avoid anyway to have
many entries in my lists at the same time. But as I understood the method
TCanvas::TextRect right, I will need to modify the TRect passed through to
the OnDrawCell event, but maybe I've misunderstood this:

-Does TextRect modify the TRect one passes through, or can I make a copy of
the TRect passed through to OnDrawCell, modify this copy and then pass it
through to TextRect?

-And why does the help say something totally different? Is there a method
with different parameters to which I haven't got access in my personal
edition or is this just a small "bug"?

/Erik


Back to top
Rudy Velthuis [TeamB]
Guest





PostPosted: Sun Jul 03, 2005 11:43 am    Post subject: Re: OnDrawCell (TStringGrid) requesting constant TRect Reply with quote



At 13:34:13, 03.07.2005, Erik Doekes wrote:

Quote:
Hi!

In the help to C++Builder Personal it is stated that the OnDrawCell
event has parameters
(TObject*, long, long, TRect, TGridDrawState)
but when try to run an application with a grid derived from TStringGrid
containing an OnDrawCell event it seems that the compiler wants
(TObject*, int, int, const TRect &, TGridDrawState)
as parameters.

The help I have has this example:

<<
The following code uses the bitmaps in an image list component to draw
the contents of each cell in a draw grid. It draws a focus rectangle
around the cell that has focus.

void __fastcall TForm1::DrawGrid1DrawCell(TObject *Sender, long Col, long
Row, TRect &Rect, TGridDrawState State)

{
long index = Row * DrawGrid1->ColCount + Col;
DrawGrid1->Canvas->Brush->Color = clNormalBackground;
DrawGrid1->Canvas->FillRect(Rect);
ImageList1->Draw(DrawGrid1->Canvas,Rect.Left,Rect.Top,index);
if (State.Contains(gdFocused))
DrawGrid1->Canvas->DrawFocusRect(Rect);
}
Quote:


--
Rudy Velthuis [TeamB] http://velthuis.homepage.t-online.de

"If it weren't for electricity we'd all be watching television by
candlelight." -- George Gobel.

Back to top
Rudy Velthuis [TeamB]
Guest





PostPosted: Sun Jul 03, 2005 12:01 pm    Post subject: Re: OnDrawCell (TStringGrid) requesting constant TRect Reply with quote



At 13:43:41, 03.07.2005, Rudy Velthuis [TeamB] wrote:

Quote:
void __fastcall TForm1::DrawGrid1DrawCell(TObject *Sender, long Col,
long Row, TRect &Rect, TGridDrawState State)

{
long index = Row * DrawGrid1->ColCount + Col;
DrawGrid1->Canvas->Brush->Color = clNormalBackground;
DrawGrid1->Canvas->FillRect(Rect);
ImageList1->Draw(DrawGrid1->Canvas,Rect.Left,Rect.Top,index);
if (State.Contains(gdFocused))
DrawGrid1->Canvas->DrawFocusRect(Rect);
}


I started BCB6, created a new VCL application (File | New | Application),
and put a TStringGrid on the form. In the Object Inspector, I selected
the Events tab, and double-clicked the empty cell beside OnDrawCell. The
IDE added a new member function:

//---------------------------------------------------------------------
void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{

}
//---------------------------------------------------------------------

So it is not "const TRect &Rect", just "TRect &Rect", which of course
allows you to modify the rect.

--
Rudy Velthuis [TeamB] http://velthuis.homepage.t-online.de

"A clever man commits no minor blunders."
- Goethe (1749-1832)

Back to top
Erik Doekes
Guest





PostPosted: Sun Jul 03, 2005 2:32 pm    Post subject: Re: OnDrawCell (TStringGrid) requesting constant TRect Reply with quote

I tried the same and it works as long as I create a StringGrid visually and
double-click OnDrawCell (and e.g. put some code there using
StringGrid1->Canvas->TextRect(Rect, ...)).

But as soon as I in my non-visual class write TRect& instead of const TRect&
I get the message
"Cannot convert 'void (_fastcall *
(_closure )(TObject*,int,int,TRect&,TGridDrawState))(TObject*,int,int,TRect&
,TGridDrawState)' to 'void (_fastcall * (_closure )(TObject*,int,int,const
TRect&,TGridDrawState))(TObject*,int,int,const TRect&,TGridDrawState)'."

What can this depend on?

/Erik

Quote:
I started BCB6, created a new VCL application (File | New | Application),
and put a TStringGrid on the form. In the Object Inspector, I selected
the Events tab, and double-clicked the empty cell beside OnDrawCell. The
IDE added a new member function:

//---------------------------------------------------------------------
void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{

}
//---------------------------------------------------------------------

So it is not "const TRect &Rect", just "TRect &Rect", which of course
allows you to modify the rect.

--
Rudy Velthuis [TeamB] http://velthuis.homepage.t-online.de

"A clever man commits no minor blunders."
- Goethe (1749-1832)



Back to top
Rudy Velthuis [TeamB]
Guest





PostPosted: Sun Jul 03, 2005 2:48 pm    Post subject: Re: OnDrawCell (TStringGrid) requesting constant TRect Reply with quote

At 16:32:52, 03.07.2005, Erik Doekes wrote:

Quote:
I tried the same and it works as long as I create a StringGrid visually
and double-click OnDrawCell (and e.g. put some code there using
StringGrid1->Canvas->TextRect(Rect, ...)).

But as soon as I in my non-visual class write TRect& instead of const
TRect& I get the message
"Cannot convert 'void (_fastcall *
(_closure
)(TObject*,int,int,TRect&,TGridDrawState))(TObject*,int,int,TRect&
,TGridDrawState)' to 'void (_fastcall * (_closure
)(TObject*,int,int,const TRect&,TGridDrawState))(TObject*,int,int,const
TRect&,TGridDrawState)'."

What can this depend on?

Probably on the include file. Problem is, that the include file has:

typedef void __fastcall (__closure *TDrawCellEvent)
(System::TObject* Sender, int ACol, int ARow,
const Types::TRect &Rect, TGridDrawState State);

This is a correct translation of the original Delphi code:

TDrawCellEvent = procedure (Sender: TObject; ACol, ARow: Longint;
Rect: TRect; State: TGridDrawState) of object;

So it seems a Delphi user won't be able to modify the rect either (it is
passed with value semantics, but in reality -- due to how the Delphi
compiler codes such calls -- passed as a reference), so const TRect& Rect
is correct after all.

It seems the IDE creates the wrong stub. I have no idea why.
--
Rudy Velthuis [TeamB] http://velthuis.homepage.t-online.de

"Good people do not need laws to tell them to act responsibly, while bad
people will find a way around the laws."
- Plato (427-347 B.C.)

Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Sun Jul 03, 2005 6:21 pm    Post subject: Re: OnDrawCell (TStringGrid) requesting constant TRect Reply with quote


"Erik Doekes" <erdo8113 (AT) student (DOT) uu.se> wrote


Quote:
In the help to C++Builder Personal it is stated that the
OnDrawCell event has parameters
(TObject*, long, long, TRect, TGridDrawState)
but when try to run an application with a grid derived
from TStringGrid containing an OnDrawCell event it seems
that the compiler wants
(TObject*, int, int, const TRect &, TGridDrawState)
as parameters.

Like most of the other examples in the help file, the function/event
signatures listed in the help file are just literal C++ translations
(probably human made rather than machine made) of the Delphi Pascal source
code that the VCL is written in. As such, the help file does not always
match what the compiler actually expects. In Delphi, the signature of the
OnDrawCell event is:

(TObject, Longint, Longint, TRect, TGridDrawState)

Which is what you see in the help file. But when passing class instances as
function parameters in C++, it is more efficient to pass them by const
reference instead of by value, so the Pascal-to-C++ convertor that BCB
implies to general HPP header files for the VCL uses const references, which
is what you are seeing the compiler expecting.

Quote:
But as I understood the method TCanvas::TextRect right, I will
need to modify the TRect passed through to the OnDrawCell event,
but maybe I've misunderstood this:

Where did you get that idea from?

Quote:
-Does TextRect modify the TRect one passes through

No. TextRect() also expects a const reference as well.

Quote:
or can I make a copy of the TRect passed through to OnDrawCell,
modify this copy and then pass it through to TextRect?

Yes. Or you can pass the original TRect directly, if you do not need to
actually change the TRect's values.

Quote:
-And why does the help say something totally different?

See above.

Quote:
Is there a method with different parameters to which I haven't got
access in my personal edition or is this just a small "bug"?

It is a documentation error, not an IDE/compiler bug. Borland's
documentation has never been as good as it should be.


Gambit



Back to top
Erik Doekes
Guest





PostPosted: Sun Jul 03, 2005 8:55 pm    Post subject: Re: OnDrawCell (TStringGrid) requesting constant TRect Reply with quote

Quote:
Is there a method with different parameters to which I haven't got
access in my personal edition or is this just a small "bug"?

It is a documentation error, not an IDE/compiler bug. Borland's
documentation has never been as good as it should be.

That's actually what I meant with "bug", that's why I used quotation marks,
but maybe that is abuse of the word "bug".
Well, I'm quite satisfied with Borland's documentation/help over all. I
think they are in the top league anyway concerning documentation, I've seen
a lot worse... (don't even mention MS Windows ;)



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.