Delphi Pages Forums

Delphi Pages Forums (http://www.delphipages.com/forum/index.php)
-   General (http://www.delphipages.com/forum/forumdisplay.php?f=2)
-   -   Change method visibility (http://www.delphipages.com/forum/showthread.php?t=104282)

Ann 11-24-2003 12:32 PM

Change method visibility
 
Is there a way to change the visibility of a method in a descendant class?

I have a class like this:

CBaseObject = class
protected
procedure MoveRelativeForward(Amount: single);
[..]
end;


and I would like to derive a new class that make the MoveRelativeForward method PUBLIC.

CVisibleObject = class(CBaseObject)
public
procedure MoveRelativeForward(Amount: single);
[..]
end;

Is it possible?
thank

MrBaseball34 11-24-2003 12:48 PM

RE: Change method visibility
 
No, but I think you may be able to write a PUBLIC method in
your decendant class that access the ancestor's private
method:

<tt>
procedure CVisibleObject.MoveRelativeForwardHelper
( Amount: Single
);
begin
inherited MoveRelativeForward(Amount);
end;
</tt>


Confusious say:
Never stand between fire hydrant and dog.

MB34

Muhammad 11-24-2003 05:05 PM

RE: Change method visibility
 
Hi...

yes it is possible easly and the same way you mentioned but don't forget to add virtual and override directives:

CBaseObject = class
protected
procedure MoveRelativeForward(Amount: single); virtual;
[..]
end;

CVisibleObject = class(CBaseObject)
public
procedure MoveRelativeForward(Amount: single); override;
[..]
end;

try it ..

Ann 11-24-2003 08:01 PM

RE: Change method visibility
 
Thank for your help. I already did like MrBaseball34. I thought there was a directive that allow to change visibility like properties:

CAncestor = class
private
FSize : integer;
protected
property Size: Integer read FSize;
end;

CDerived = class(CAncestor)
public
property Text;
end;

ann


All times are GMT. The time now is 12:18 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.