Solved

Overriding Private methods

Posted on 1997-12-15
3
498 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
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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

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…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

831 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