各位大师,我现在定义了一个shape数组,全部用create函数产生在屏幕上了,但是我希望能定义OnMouseUp函数,能够在我点击任何一个shape时都在状态栏显示相关信息,比如第一个显示1,第二个显示2。我用class第一新的类,但是不知道怎么定义OnMouseUp的函数,请各位大侠指点。
     谢谢。

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;type
      TForm1 = class(TForm)
        procedure ShapeMouseUp(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.ShapeMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      ShowMessage(IntToStr(TShape(Sender).Tag));
    end;procedure TForm1.FormCreate(Sender: TObject);
    var ShapeArr:array[1..10]of TShape;
        i:integer;
    begin
      for i:=1 to 10 do
         begin
          ShapeArr[i]:=TShape.Create(self);
          with ShapeArr[i] do
             begin
               Top:=i*30;
               Parent:=Form1;
               Tag:=i;
               Show;
               OnMouseUp:=ShapeMouseUp;
             end;
         end;
    end;end.