大家好,我的程序如下:
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  TForm1 = class(TForm)
    TMyListBox = class(TListBox)
    private
        procedure MouseIntoListBox(var Msg:TMessage); message CM_MOUSEENTER;
        procedure MouseLeaveListBox(var Msg:TMessage); message CM_MOUSELEAVE;
        procedure DrawInListBox(Color:TColor;const s:string);
    end;
    procedure FormCreate(Sender: TObject);
    private
     { Private declarations }
    public
     { Public declarations }
    end;var
  Form1: TForm1;
  MyListBox: TMyListBox;
  row:integer;implementation{$R *.dfm}        procedure TMyListBox.DrawInListBox(Color:TColor;const s:string);
        begin
                MyListBox.Canvas.Font.Color := Color;
                MyListBox.Canvas.Font.Size := 13;
                MyListBox.Canvas.Font.Style := [fsBold];
                MyListBox.Canvas.TextOut(10,row,s);
                Inc(row, 25);
        end;        procedure TMyListBox.MouseIntoListBox(var Msg:TMessage);
        begin
                DrawInListBox(clGreen, '鼠标移入列表框');
        end;        procedure TMyListBox.MouseLeaveListBox(var Msg:TMessage);
        begin
                DrawInListBox(clNavy, '鼠标移出列表框');
        end;        procedure TForm1.FormCreate(Sender: TObject);
        begin
                MyListBox := TMyListBox.Create(Self);
                MyListBox.Parent := Self;
                MyListBox.Width := Self.ClientWidth div 2;
                MyListBox.Align := alLeft;
                row := 10;
        end;end.
我想在form内添加一个ListBox,但是一直出现“Expected ':' but '=' found”,是什么原因呢?谢谢!

解决方案 »

  1.   

        TMyListBox = class(TListBox) 
        private 
            procedure MouseIntoListBox(var Msg:TMessage); message CM_MOUSEENTER; 
            procedure MouseLeaveListBox(var Msg:TMessage); message CM_MOUSELEAVE; 
            procedure DrawInListBox(Color:TColor;const s:string); 
        end; 
    把这一段移到TForm1这个类的外面
      

  2.   

    我按照corn1的方法移动代码后,出现了:
    Class TListBox not found的错误,请问是什么原因呢?
      

  3.   

    应该不会啊,StdCtrls单元你也已经引用了
    奇怪
      

  4.   

    我修改后的代码是:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
        private
         { Private declarations }
        public
         { Public declarations }
        end;  TMyListBox = class(TListBox)
        private
            procedure MouseIntoListBox(var Msg:TMessage); message CM_MOUSEENTER;
            procedure MouseLeaveListBox(var Msg:TMessage); message CM_MOUSELEAVE;
            procedure DrawInListBox(Color:TColor;const s:string);
        end;var
      Form1: TForm1;
      MyListBox: TMyListBox;
      row:integer;implementation{$R *.dfm}        procedure TMyListBox.DrawInListBox(Color:TColor;const s:string);
            begin
                    MyListBox.Canvas.Font.Color := Color;
                    MyListBox.Canvas.Font.Size := 13;
                    MyListBox.Canvas.Font.Style := [fsBold];
                    MyListBox.Canvas.TextOut(10,row,s);
                    Inc(row, 25);
            end;        procedure TMyListBox.MouseIntoListBox(var Msg:TMessage);
            begin
                    DrawInListBox(clGreen, '鼠标移入列表框');
            end;        procedure TMyListBox.MouseLeaveListBox(var Msg:TMessage);
            begin
                    DrawInListBox(clNavy, '鼠标移出列表框');
            end;        procedure TForm1.FormCreate(Sender: TObject);
            begin
                    MyListBox := TMyListBox.Create(Self);
                    MyListBox.Parent := Self;
                    MyListBox.Width := Self.ClientWidth div 2;
                    MyListBox.Align := alLeft;
                    row := 10;
            end;end.
      

  5.   

    楼主 你的delphi有问题
    你的代码我复制到我的delphi里编译运行
    完全没问题
    建议你新建一个工程 然后直接把这些代码复制进去就行了