0

I'm using a visual component TJvListView from the JEDI JVCL library. Here are the relevant declarations of this component class:

TJvListView = class(TJvExListView)
private
  FOnSaveProgress: TJvOnProgress;
public
  procedure SaveToStrings(Strings: TStrings; Separator: Char);

What I'm trying to do is replace the SaveToStrings() method with my own modified definition. I tried to do this using the "interposer" class way:

uses
  JvListView
type
  TJvListView = class(JvListView.TJvListView)
  public
    procedure SaveToStrings(Strings: TStrings; Separator: Char);
  end;

  TfrmFaultMemView = class(TForm)
    lvFMEs: TJvListView;
  end;

procedure TJvListView.SaveToStrings(Strings: TStrings; Separator: Char);
begin
  if Assigned(Self.FOnSaveProgress) then  // COMPILER ERROR HERE
  begin
  end;
end;

The original method depends on accessing some private members of the class, and I have to keep that code in my modified definition.

However, when I try to compile this it gives me an error:

E2361 Cannot access private symbol TJvListView.FOnSaveProgress

I'm tryin to re-define a public method, but it's unavoidable that they must access private members/methods. Given that, how can I overload that method with my own definition?

Community
  • 1
  • 1
DBedrenko
  • 4,871
  • 4
  • 38
  • 73

1 Answers1

3

Instead of using private field FOnSaveProgress use published property OnSaveProgress

When you extend class you can only access it's protected, public or published members. Private members are, well, private and cannot be accessed not even from extending class. The only place where you can access private members from other class is if both classes are in same unit and members are not marked as strict private.

Dalija Prasnikar
  • 27,212
  • 44
  • 82
  • 159
  • Thanks for the feedback. I'm not sure I can use that property; I'm trying to keep the code as close to the functionality of the original, and the [original](https://github.com/project-jedi/jvcl/blob/9d1976ea193e14b54a725819a9b12bb102be71e2/jvcl/run/JvListView.pas#L1612) accesses that private member directly. – DBedrenko Mar 17 '16 at 14:28
  • Using property or field in this case is the same. – Dalija Prasnikar Mar 17 '16 at 14:29
  • Ah yes, it looks like you're right :) I appreciate the help – DBedrenko Mar 17 '16 at 14:31