Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inherited class

Status
Not open for further replies.

tvidigal

Programmer
Sep 8, 2003
19
0
0
PT
:) hello again, today i'm a breeze for topics :cool:

I often see c++, class declarations like this:

MyClass : DoSomething :: MyParentClass {...}

then to use functions from the myParentClass we just have to do

MyParentClass->MyParentClassFunction

do we have in delphi the same structure or, even if our class inherits from another like:

Type
TMyClass = Class(TMyParentClass)
.....
public private protected end;

we still have to create the a new obj on constructor:

constructor MyClass.Create();
begin
inherited Create();
myGlobalParentClass := TMyParentClass.Create();
end;

and use it from there!

thank you very much!
Best Regards
 
huh?

I'm afraid I do not write a lot of C++ code these days - and haven't for years :) so am unsure what:

MyClass : DoSomething :: MyParentClass {...}

declaration means....

if you are equating it to simple inheritence:

TMyClass = class(TMyParentClass)
...

then I don't see why you are creating the parent class for in the constructor.

If you are simply wanting the child class to inherit some of the parents functions, then you are going about it the wrong way.

e.g.

TRectangle = class(TObject)
protected
FTop: integer;
FLeft: integer;
FWidth: integer;
FHeight: integer;

procedure Draw();
procedure SetHeight(AHeight: integer); virtual;
procedure SetWidth(AWidth: integer); virtual;
public
constructor Create();

procedure Move(x,y: integer);

property Height: integer read FHeight write SetHeight;
property Width: integer read FWidth write SetWidth;
end;

TSquare = class(TRectangle)
protected
procedure SetHeight(AHeight: integer); override;
procedure SetWidth(AWidth: integer); override;
end;

if I create a TSquare class, I can still call the move method as it is inherited.

var
Square: TSquare;
begin
Square := TSquare.Create();
Square.Height := 10;
Square.Move(1,1);
end;


In the TSquare constructor:

procedure TSquare.Create();
begin
inherited;

FLeft := 0;
FTop := 0;
FWidth := 0;
FHeight := 0;
end;

You don't need to create a TRectangle within the TSquare's constructor in order to call the Move method.


Hope that helps...if not, can you clarify your question.

Cheers.
 
Hi,
thanks for the reply!

i did understand what's needed altough some syntax like
this one:
MyClass :: MyClass() : MyParentClass()
{
MyParentClass::setCoefficients( 1, 2, 3, 4 );
this->setCoefficients( 1, 2, 3, 4 );
}
still make my mind blow!! :)

thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top