Solved

Overriding/hiding inherited published properties

Posted on 1999-01-11
6
851 Views
Last Modified: 2010-04-06
I am making a component that is a descendent of TDrawGrid.

Lets say that I want these properties (among others) to be published:  Width, Height, ColCount, RowCount.

When the user changes one of these, I want the methods found in DrawGrid to take care of it.  However, before this is done, I need my component to take care of some other things, such as memory allocation.

For example, say that the user increases RowCount by 1.  I need to allocate additional memory and do some other things (for the purpose of my component), and then let TDrawGrid do whatever is needed to change the rows.

How would I hide the inherited properties, and include new properties of the same name that call the inherited properties?  I think I should use the "inherited" keyword, but I am not exactly sure.

Another, similar question:

How would I hide (i.e. make private to my component) any inherited published properties, yet still make them available to my component?

For example, lets say I wanted to make Height and Width (in DrawGrid) totally unavailable to the user and other components, but I want to retain them for private use by my component.  How would I do that?

If it matters, I am using Delphi 2.
0
Comment
Question by:scrapdog
  • 3
  • 3
6 Comments
 
LVL 20

Accepted Solution

by:
Madshi earned 60 total points
ID: 1356000
Hi scrapdog,

look at this example, it combines your both questions. The Width property is overriden by your own functions, but these functions call the inherited Width property. AND - your Width property is NOT available to other units.

type
  TScrapDogsDrawGrid = class(TEdit)
  private
    function  GetWidth : integer;
    procedure SetWidth(const value: integer);
    property  Width : integer read GetWidth write SetWidth;
  end;

procedure TScrapDogsDrawGrid.SetWidth(const value: integer);
begin
  // here do your stuff
  inherited Width:=value;
  // or here
end;

function TScrapDogsDrawGrid.GetWidth : integer;
begin
  // here do your stuff
  result:=inherited Width;
  // or here
end;

Regards, Madshi.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1356001
Of course you should change (TEdit) to (TDrawGrid)...  :-)
0
 
LVL 5

Author Comment

by:scrapdog
ID: 1356002
OK.  Thanks.  Just a couple of things I need clarified.

1.  If I DID want to make the Width property (the new property for my component, as shown in your code) visible to others, I just simply move it from private to public or published, right?

2.  Let's say I wanted to totally hide FixedRows and not do anything with it.  All I want to do is keep the user from changing it.  Do I simply exclude it from my property definitions, or is there more to it?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Author Comment

by:scrapdog
ID: 1356003
Adjusted points to 65
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1356004
(1) That's right...  :-)
(2) Hmmm. If you derive your component from TDrawGrid then your component will have all properties published, that TDrawGrid published, too. That means you have to DO something in order to hide such a property.
You could try just this:
  private
    FixedRows;
  public
Perhaps that's all. I'm not sure about that. If it doesn't work, then use the same stuff as I showed you with the Width property, but just leave your GetFixedRows/SetFixedRows functions empty.

Regards, Madshi.
0
 
LVL 5

Author Comment

by:scrapdog
ID: 1356005
Thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now