How to override a method when the compiler says that it is "not found in the base class"?

I have a custom component that I create that is derived from TCustomListView.

I need to override a method, in particular a method GetImageIndex, but I cannot access it.

The component that I create should behave like TListView, but without a lot of published properties and methods that it has, since I will create my own component, so I get it instead TCustomListView.

In my component, I tried to access GetImageIndexas follows:

TMyListView = class(TCustomListView)
  strict protected
    procedure GetImageIndex(Sender: TObject; Item: TListItem); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
end;

procedure TMyListView.GetImageIndex(Sender: TObject; Item: TListItem);
begin
  inherited;
  // Make my changes
end;

Obviously, the above is abbreviated for the purposes of the example.

I encounter a compilation error:

Method GetImageIndexnot found in base class

? , , , , ?


, , . -, , 1, .

:

protected
    procedure GetImageIndex(Sender: TObject; Item: TListItem); // note not to override

:

constructor TMyListView.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  OnGetImageIndex := GetImageIndex;
end;

, , , .

+4
1

TCustomListView.GetImageIndex - . .

:

  • OnGetImageIndex.
  • LVN_GETDISPINFOA LVN_GETDISPINFOW CN_NOTIFY .

. :

type
  TMyListView = class(TCustomListView)
  protected
    procedure CNNotify(var Message: TWMNotifyLV); message CN_NOTIFY;
  end;
....
procedure TMyListView.CNNotify(var Message: TWMNotifyLV);
begin
  case Message.NMHdr.code of
  LVN_GETDISPINFOA, LVN_GETDISPINFOW:
    ; // add your customisation here
  else
    inherited;
  end;
end;

, , . .

+8

Source: https://habr.com/ru/post/1546572/


All Articles