Watch, Follow, &
Connect with Us

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


Welcome, Guest
Guest Settings
Help

Thread: How do I use public type/const in classes



Permlink Replies: 3 - Last Post: Apr 15, 2016 9:37 AM Last Post By: Peter Below Threads: [ Previous | Next ]
John Kouraklis

Posts: 209
Registered: 3/10/01
How do I use public type/const in classes
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 11, 2016 12:36 PM
Hi guys,

I am afraid I need your help...again :-)

I have subclassed an FMX component and I want to override a (Virtual) protected procedure.

This procedure has a number of params, which are declared as "public type" in the class of the component, say TAbc.

When I try to override the procedure, I get an error that the TAbc is not declared although my component subclasses the original one. Shouldn't I be able to get access to Tabc?

Then, I redeclared Tabc as public type in my new class but not the compiler says that the declaration differs from the one in the base class.

Can you please help me with this?

Thanks a lot.

John
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: How do I use public type/const in classes
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 13, 2016 9:43 AM   in response to: John Kouraklis in response to: John Kouraklis
John Kour wrote:

Hi guys,

I am afraid I need your help...again :-)

I have subclassed an FMX component and I want to override a (Virtual)
protected procedure.

This procedure has a number of params, which are declared as "public
type" in the class of the component, say TAbc.

When I try to override the procedure, I get an error that the TAbc is
not declared although my component subclasses the original one.
Shouldn't I be able to get access to Tabc?

Definitely. You have to show the real declarations for us to diagnose
this, however.


--
Peter Below
TeamB

John Kouraklis

Posts: 209
Registered: 3/10/01
Re: How do I use public type/const in classes
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 14, 2016 4:07 PM   in response to: Peter Below in response to: Peter Below
Peter Below wrote:
John Kour wrote:

Hi guys,

I am afraid I need your help...again :-)

I have subclassed an FMX component and I want to override a (Virtual)
protected procedure.

This procedure has a number of params, which are declared as "public
type" in the class of the component, say TAbc.

When I try to override the procedure, I get an error that the TAbc is
not declared although my component subclasses the original one.
Shouldn't I be able to get access to Tabc?

Definitely. You have to show the real declarations for us to diagnose
this, however.


--
Peter Below
TeamB


Hi Peter,

you're right.

The code goes like this:

type
  TBaseClass  = class
  public
    type
       TAbc = (Left, Right)
       ....
    procedure Update(const tmpAbc: TAbc); virtual;
   ....
   end;
 
  TMyClass = class(TBaseClass)
   public
     procedure Update(const tmpAbc: TAbc); override;
   ....
   end;
 


However, I found out what I should do. I had to reference the base class, like this:

  procedure Update(const tmpAbc: TBaseClass.TAbc); override;


Now, I've got another question. Is it possible to extent TAbc? Like declaring TAbc = (Left, Middle, Right) in MyClass?

I suppose this will override the initial definition, right? Or, it shouldn't work at all?

Thanks

John
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: How do I use public type/const in classes
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 15, 2016 9:37 AM   in response to: John Kouraklis in response to: John Kouraklis
John Kour wrote:

Peter Below wrote:
John Kour wrote:

Hi guys,

I am afraid I need your help...again :-)

I have subclassed an FMX component and I want to override a
(Virtual) protected procedure.

This procedure has a number of params, which are declared as
"public type" in the class of the component, say TAbc.

When I try to override the procedure, I get an error that the
TAbc is not declared although my component subclasses the
original one. Shouldn't I be able to get access to Tabc?

Definitely. You have to show the real declarations for us to
diagnose this, however.


--
Peter Below
TeamB


Hi Peter,

you're right.

The code goes like this:

type
  TBaseClass  = class
  public
    type
       TAbc = (Left, Right)
       ....
    procedure Update(const tmpAbc: TAbc); virtual;
   ....
   end;
 
  TMyClass = class(TBaseClass)
   public
     procedure Update(const tmpAbc: TAbc); override;
   ....
   end;
 


However, I found out what I should do. I had to reference the base
class, like this:

  procedure Update(const tmpAbc: TBaseClass.TAbc); override;


Now, I've got another question. Is it possible to extent TAbc? Like
declaring TAbc = (Left, Middle, Right) in MyClass?

I suppose this will override the initial definition, right? Or, it
shouldn't work at all?

The declaration will probably work but it will hide the one inherited
from the base class, and that will make it impossible to use TAbc.Right
as a value for a call to Update, for instance.

Enumerated types are ordinal types and cannot be extended as such. You
define new types as subranges of an existing enumeration, though,
that is: restrict an existing enumeration. Elements of the subrange
will be assignment-compatible with variables/parameters of the base
type, but not vice versa.


--
Peter Below
TeamB

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02