ID not member of Parent class

I have created a new class derived from TPanel:

class PACKAGE TTerminal : public TPanel
{
private:

protected:

public:
__fastcall TTerminal(TComponent* Owner);

int FCableType;
__property int CableType = {read = FCableType, write = FCableType};


TLine[rc][0] = new TTerminal(this);
TLine[rc][0]->Parent = this;

TLine[rc][0]->CableType = T1->FieldByName("Type")->AsInteger;

Now, when I try to access this member (CableType), I get the message
[BCC32 Error] TSDInfoF.cpp(509): E2316 'CableType' is not a member of 'TPanel'

I have been looking, but cannot figure out what I am doing wrong.
1
2
int FCableType;
__property int CableType = {read = FCableType, write = FCableType};


Is this C++/CLI or something? C++ doesn't have properties in the same sense that C# does.

Anyway it sounds like TLine is a TPanel and not a TTerminal. You can't access derived members from a parent reference/pointer/object.

Consider the following:

1
2
3
TPanel* foo = new Some_Other_type_Thats_derived_from_TPanel_but_doesnt_have_a_CableType_member;

foo->CableType = whatever; // <- how could this work? 


Because of this you either need to downcast to TTerminal (ew), or change TLine so that it points to TTerminals instead of TPanels (probably not what you want). Or better yet, initialize this object via a TTerminal before giving it to TLine:

1
2
3
4
5
TTerminal* temp = new TTerminal(this);
temp->Parent = this;
temp->CableType = T1->FieldByName("Type")->AsInteger;

TLine[rc][0] = temp;



Of course... all this initialization should probably be in TTerminal's ctor anyway -- so that's another way you could go.
Right you are!
I had declared TLine as a TPanel, should have been a no-brainer.
THANKS!

By the way, this is C++.

If you think I'm doing something wrong otherwise, please do not hesitate to enlighten me.
By the way, this is C++.


It isn't. It must be some kind of compiler extension or something. It won't compile in most C++ compilers.

the whole __property thing is not standard C++. It sounds like it's an MSVS extension. Be weary of anything that starts with two underscores.
Topic archived. No new replies allowed.