Непонятно, зачем ты внутри класса создаешь экземпляр этого же класса? А проблема в том, что экземпляр класс ты объявил (ListView1: MyListView), но не создал его (ListView1 := MyListView.Create). Вот и вылетает ошибка…
А вообще, я бы обошелся без этого… Вот так:
Код:
unit MyListView;
interface
uses
SysUtils, Classes, Controls, ComCtrls, Windows, Messages, Variants, Graphics, Forms,
Dialogs;
type
TMyListView = class(TListView)
procedure ListView1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
private
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
published
{ Published declarations }
end;
procedure Register;
implementation
procedure TMyListView.ListView1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
inherited;
if Key = VK_RETURN then
if Self.SelCount = 1 then
Self.Selected.Caption := 'Мой текст';
end;
procedure Register;
begin
RegisterComponents('Test', [TMyListView]);
end;
constructor TMyListView.Create(aOwner: TComponent);
begin
inherited;
OnKeyUp := ListView1KeyUp;
end;
end.