 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Yavuz Ozturk Guest
|
Posted: Sat Mar 26, 2005 12:37 pm Post subject: How to access protected member properties? |
|
|
Hi all,
I need to access the RowHeights PROTECTED variable of TDBGrid. I found an
example code written in DELPHI. Unfotunately, I don' t know how to convert
this Delphi code to C++Builder code. The delphi code is as under:
//Suppose that a TDBGrid component is put on the form having the name
DBGrid1.
type THackDBGrid = class(TDBGrid)
procedure TForm1.OnActivate(TObject Sender)
begin
THackDBGrid(DBGrid1).RowHeights[0] := 20;
end;
Here I need to say something to those who are new to C++Builder. Normally,
you can NOT write DBGrid1->RowHeights[0] = 20 (compiler will give some
error) because RowHeights property of TDBGrid is protected. Protected
properties can not be accesses through the objects. Protected properties can
only be accessed through functions of classes derived from the class having
that protected variable. But in the above code, the TDBGrid class is hacked
and the compiler allowed the programmer to access PROTECTED RowHeights
property.
If anyone can convert this DELPHI code to C++BUILDER code, I will be very
happy :)
-Cheers
-Yavuz (My name)
|
|
| Back to top |
|
 |
Damon Chandler (TeamB) Guest
|
Posted: Sat Mar 26, 2005 7:26 pm Post subject: Re: How to access protected member properties? |
|
|
Hi Yavuz,
Here's the translation...
class THackDBGrid : public TDBGrid
{
public:
__property RowHeights;
};
To use the property...
static_cast<THackDBGrid*>(DBGrid1)->RowHeights[0] = 20;
If you find that you need to access more properties in this way, I'd
suggest creating and registering your own TDBGrid descendant component.
Good luck,
--
Damon (TeamB)
C++Builder Developer's Journal
http://bcbjournal.com
BCB Commonly Asked Questions
http://bcbjournal.com/bcbcaq
Yavuz Ozturk wrote:
| Quote: | Hi all,
I need to access the RowHeights PROTECTED variable of TDBGrid. I found an
example code written in DELPHI. Unfotunately, I don' t know how to convert
this Delphi code to C++Builder code. The delphi code is as under:
|
|
|
| Back to top |
|
 |
Yavuz Ozturk Guest
|
Posted: Sat Mar 26, 2005 7:34 pm Post subject: Re: How to access protected member properties? |
|
|
Thank you Damon,
Your code snippet worked AMAZING !!! ))
I knew that the solution can be get by using static_cast or dynamic_cast.
But I failed to used them.
Moreover, I read static_cast and dynamic_cast from the help but I didn' t
understand them. If you don' t mind, can you explain them briefly.
-Thank you again for your attention.
-Best regards.
-Yavuz
"Damon Chandler (TeamB)" <editor (AT) _REMOVE_THIS_SPAM_GUARD_bcbjournal (DOT) com>
wrote in message news:4245b76b (AT) newsgroups (DOT) borland.com...
| Quote: | Hi Yavuz,
Here's the translation...
class THackDBGrid : public TDBGrid
{
public:
__property RowHeights;
};
To use the property...
static_cast<THackDBGrid*>(DBGrid1)->RowHeights[0] = 20;
If you find that you need to access more properties in this way, I'd
suggest creating and registering your own TDBGrid descendant component.
Good luck,
--
Damon (TeamB)
C++Builder Developer's Journal
http://bcbjournal.com
BCB Commonly Asked Questions
http://bcbjournal.com/bcbcaq
Yavuz Ozturk wrote:
Hi all,
I need to access the RowHeights PROTECTED variable of TDBGrid. I found an
example code written in DELPHI. Unfotunately, I don' t know how to
convert this Delphi code to C++Builder code. The delphi code is as under:
|
|
|
| Back to top |
|
 |
|
|
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
|
|