Solved

Overriding Private methods

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

708 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

14 Experts available now in Live!

Get 1:1 Help Now