Показать сообщение отдельно
  #7  
Старый 04.06.2007, 10:21
Аватар для Decoding
Decoding Decoding вне форума
Местный
 
Регистрация: 03.06.2006
Адрес: Почту найдете на моем сайте
Сообщения: 576
Версия Delphi: D10.2
Репутация: 214
По умолчанию

Непонятно, зачем ты внутри класса создаешь экземпляр этого же класса? А проблема в том, что экземпляр класс ты объявил (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.
Ответить с цитированием