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
Solved

Overriding Private methods

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
add combobox item based on numbers 9 154
Magic Software info 18 138
Dev Express grid collapse 2 45
TEMBEDDEDWB how can i change its user agent ? 8 69
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 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