Link to home
Start Free TrialLog in
Avatar of Matvey
Matvey

asked on

Overriding Private methods

I have to override a private method :

TTrackBar
Priate
  procedure SetPosition(Value: Integer) of TTrackBar

How ?
ASKER CERTIFIED SOLUTION
Avatar of julio011597
julio011597

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ra_tim
ra_tim

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;


 
Avatar of Matvey

ASKER

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.