Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Cannot access a parent protected property from a child class using bcc64



Permlink Replies: 4 - Last Post: Feb 5, 2015 4:49 AM Last Post By: Jean-Milost Rey...
Jean-Milost Rey...

Posts: 23
Registered: 11/8/11
Cannot access a parent protected property from a child class using bcc64
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 2, 2015 3:17 PM
Hello,

I tried to compile my component package in 64 bit, however I'm blocked by a very strange compilation error:
[C++ Error] WTGroupBox.cpp(1337, 26): 'AutoSize' is a protected member of 'Vcl::Controls::TControl'

However, my WTGroupBox class inherits from TGroupBox, and TGroupBox itself inherits from Vcl::Controls::TControl. I declared my property as follow:
__property bool AutoSize = {read = GetAutoSize, write = SetAutoSize, default = false};


and here are my getter and setter functions
in .h
    ...
        typedef TGroupBox inherited;
    ....
        virtual bool __fastcall GetAutoSize() const;
 
        virtual void __fastcall SetAutoSize(bool value);
    ...


in .cpp
...
//---------------------------------------------------------------------------
bool __fastcall WTGroupBox::GetAutoSize() const
{
    return inherited::AutoSize;
}
//---------------------------------------------------------------------------
void __fastcall WTGroupBox::SetAutoSize(bool value)
{
    ....
    inherited::SetAutoSize(value);
    ....
}
//---------------------------------------------------------------------------
...


The error appear when I try to compile the GetAutoSize() function. As I know, a child class should be able to call a protected parent function. In addition, this code can be compiled without problems in 32 bit. So what is the problem? Why it's no more possible to access a parent protected member inside a child class? Or it is a bcc64 bug?

Regards

Edited by: Jean-Milost Reymond on Feb 2, 2015 3:18 PM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Cannot access a parent protected property from a child class usingbcc64 [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 3, 2015 11:44 AM   in response to: Jean-Milost Rey... in response to: Jean-Milost Rey...
Jean-Milost wrote:

I declared my property as follow:

You don't need to declare your own getter/setter methods that simply delegate
to the inherited getter/setter methods. Get rid of your getter/setter methods
altogether and just promote the existing property as-is:

__published:
    __property AutoSize;


That is all you need.

The error appear when I try to compile the GetAutoSize() function.
As I know, a child class should be able to call a protected parent
function.

There is no parent getter method for the AutoSize property, the getter is
a direct data member access, and the data member in question is declared
as private.

--
Remy Lebeau (TeamB)
Jean-Milost Rey...

Posts: 23
Registered: 11/8/11
Re: Cannot access a parent protected property from a child class usingbcc64 [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 4, 2015 11:17 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Hi Remy

Thank you for the answers

Remy Lebeau (TeamB) wrote:
You don't need to declare your own getter/setter methods that simply delegate to the inherited getter/setter methods
In my case that's useful, because I need to change some things in the getter/setter code

Remy Lebeau (TeamB) wrote:
__published:
__property AutoSize;
I tried this too, but I'm confused, because when I try to access to my property in this condition, I receive another error:
[C++ Error] cannot read a property that has no read specifiers

The most confusing is that properties declared as above works very well in VCL header files. The only notable difference between this code and mine is that I declare my classes using PACKAGE, whereas VCL use PASCALIMPLEMENTATION (that's normal, because VCL is written in Delphi). Or should I use both declarations in my classes?

As reminder, my code compiles without problems using bcc32. This happens only when I try to compile using bcc64. I really don't know what is wrong.

Regards
Martin Nijhoff

Posts: 75
Registered: 8/26/10
Re: Cannot access a parent protected property from a child class using bcc64
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 5, 2015 2:02 AM   in response to: Jean-Milost Rey... in response to: Jean-Milost Rey...
Hi Jean-Milost,

Jean-Milost Reymond wrote:
However, my WTGroupBox class inherits from TGroupBox, and TGroupBox itself inherits from Vcl::Controls::TControl. I declared my property as follow:
__property bool AutoSize = {read = GetAutoSize, write = SetAutoSize, default = false};


All TGroupBox does, is hoist protected properties it inherits from TCustomGroupBox.

You should derive your control from TCustomGroupBox instead of TGroupBox, and simply hoist the AutoSize property:

class PACKAGE WTGroupBox : public TCustomGroupBox
{
    typedef TCustomGroupBox inherited;
 
    ...
 
    __published:
        __property AutoSize;    // Hoists the property, so that it is visible in the Object Inspector.
}


Please note that you don't specify a type when hoisting a property.

Jean-Milost Reymond wrote:

and here are my getter and setter functions
in .h
    ...
        typedef TGroupBox inherited;
    ....
        virtual bool __fastcall GetAutoSize() const;
 
        virtual void __fastcall SetAutoSize(bool value);
    ...


in .cpp
...
//---------------------------------------------------------------------------
bool __fastcall WTGroupBox::GetAutoSize() const
{
    return inherited::AutoSize;
}
//---------------------------------------------------------------------------
void __fastcall WTGroupBox::SetAutoSize(bool value)
{
    ....
    inherited::SetAutoSize(value);
    ....
}
//---------------------------------------------------------------------------
...


Can you tell us what exactly you try to accomplish?

Do you need additional processing when the AutoSize property is changed or when the groupbox is auto-sized?

If the latter is the case, you might be better off overriding the AdjustSize() or CanAutoSize() methods instead.

--
Martin
Jean-Milost Rey...

Posts: 23
Registered: 11/8/11
Re: Cannot access a parent protected property from a child class using bcc64
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 5, 2015 4:43 AM   in response to: Martin Nijhoff in response to: Martin Nijhoff
Hi Martin,

Thank you for your answer

Martin Nijhoff wrote:
Can you tell us what exactly you try to accomplish?
Nothing magical. Simply compile inherited::AutoSize = true in a class derived from a TGroupBox in 64 bit. The problem appear in any place I write this instruction.

So, to avoid all confusions, we will withdraw that getter / setter question, because it's not really the problem ultimately. Here is a minimal code (compilable) with the problem

.h
#ifndef WTGroupBoxH
#define WTGroupBoxH
 
#include <Vcl.StdCtrls.hpp>
 
class PACKAGE WTGroupBox : public TCustomGroupBox
{
    __published:
 
    public:
        typedef TCustomGroupBox inherited;
 
        __fastcall WTGroupBox(TComponent* pOwner);
        virtual __fastcall ~WTGroupBox();
};
#endif


.cpp
#include <vcl.h>
#pragma hdrstop
#include "WTGroupBox.h"
 
//---------------------------------------------------------------------------
static inline void ValidCtrCheck(WTGroupBox*)
{
    new WTGroupBox(NULL);
}
//---------------------------------------------------------------------------
__fastcall WTGroupBox::WTGroupBox(TComponent* pOwner) : TCustomGroupBox(pOwner)
{
    inherited::AutoSize = true;
}
//---------------------------------------------------------------------------
__fastcall WTGroupBox::~WTGroupBox()
{}
//---------------------------------------------------------------------------


When I try to compile this code in 64 bit, I receive the following errors:
[C++ Error] WTGroupBox.cpp(13, 15): 'AutoSize' is a protected member of 'Vcl::Controls::TControl'
[C++ Error] Vcl.Controls.hpp(1544, 17): must name member using the type of the current context 'WTGroupBox'

Note that the same code compiles well in 32 bit. I wonder if somebody can explain this for me.

Note: I'm using Embarcadero® RAD Studio XE7 Version 21.0.17017.3725, WITHOUT update 1. The code above is compiled inside a package project, build type = Debug, target = Windows 64-bit

Regards

Edited by: Jean-Milost Reymond on Feb 5, 2015 4:48 AM
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02