Solved

Overriding Private methods

Posted on 1997-12-15
3
528 Views
Last Modified: 2010-04-04
I have to override a private method :

TTrackBar
Priate
  procedure SetPosition(Value: Integer) of TTrackBar

How ?
0
Comment
Question by:Matvey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Accepted Solution

by:
julio011597 earned 0 total points
ID: 1353696
You cannot override a private method.
To override a method, the method must be, at least, protected (so that your inherited component can see it), and virtual (so that it may be overriden).

Anyway you can _hide_ it, i.e. redeclare it in your inherited component.
Consider, anyway, that you'll lose the chance to call the inherited method by the 'inherited' keyword.

HTH, julio
0
 

Expert Comment

by:ra_tim
ID: 1353697
Maybe it is possible to hack in the RTTI, the Delphi Runtime information.

To access a local variable is simple:

// TClass1 contains a private variable
TClass1 = class
  private
    FSecret : integer;
end;

// TClass2 is a has the same structure (and byte organisation)
// as TClass1 only that members are public.

TClass2 = class
  public
     FSecret : integer;
end;

procedure Hack;
var a : TClass1;
begin
  a := TClass1.Create;
  TClass2(a).FSecret := 100;
  // This cast makes it possible to access a private variable
end;


 
0
 
LVL 3

Author Comment

by:Matvey
ID: 1353698
Thank you ra_tim, but what I need is to add some code to a private method after I call the Inherited method (or get the method do whatever it has to do any other way).
But anyway, I can copy the source code of that private method, rewrite it in my control and do the thing you say.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

726 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