Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 11-24-2003, 12:32 PM
Ann Ann is offline
Junior Member
 
Join Date: Nov 2003
Posts: 4
Default 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
Reply With Quote
  #2  
Old 11-24-2003, 12:48 PM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default 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:


procedure CVisibleObject.MoveRelativeForwardHelper
( Amount: Single
);
begin
inherited MoveRelativeForward(Amount);
end;



Confusious say:
Never stand between fire hydrant and dog.

MB34
Reply With Quote
  #3  
Old 11-24-2003, 05:05 PM
Muhammad Muhammad is offline
Senior Member
 
Join Date: Jan 2003
Posts: 399
Default 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 ..
Reply With Quote
  #4  
Old 11-24-2003, 08:01 PM
Ann Ann is offline
Junior Member
 
Join Date: Nov 2003
Posts: 4
Default 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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 09:46 AM.


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