var
   aaa:myclass
begin
   aaa:=myclass.create;
   ...........
   aaa.free;
end;

解决方案 »

  1.   

    同意楼上,只作小修改.
    var
       aaa:myclass
    begin
       aaa:=myclass.create;
       try
         ...........
       finally
         aaa.free;
       end;
    end;
      

  2.   

    同意 hkhurus(野牛哥哥) 
    或者
    with myclass.create do
    begin
       try
         ...........
       finally
         aaa.free;
       end;
    end;
      

  3.   

    我不是这个意思
     比如实例的个数是不确定的
      var中就无法声明
      有没有直接分配内存然后创建对象
    想创建多少就多少
      

  4.   

    Tlist
    可以存储对象吗
    给个详细的例子好吗?
      

  5.   

    这是我刚刚写的一段代码,应该能满足你的功能
    VAR
      Form1             : TForm1;
      AllControl        : Tlist;IMPLEMENTATION{$R *.DFM}PROCEDURE TForm1.FormCreate(Sender: TObject);
    BEGIN
      AllControl :=Tlist.create();
    END;PROCEDURE TForm1.FormDestroy(Sender: TObject);
    BEGIN
      AllControl.free();
    END;PROCEDURE TForm1.BitBtn1Click(Sender: TObject);
    VAR
      index             : integer;
    BEGIN
      index := Allcontrol.Add(tButton.Create(self));
      WITH Tbutton(AllControl.Items[index]) DO
      BEGIN
        caption := Format('测试%d', [index]);
        parent := self;
        left := 0;
        top := 50 * index + 10;
        width := 50;
        height := 50;
        tag := index;
        onClick := self.ButtonClick;        //事件处理
        visible := true;
      END;END;PROCEDURE TForm1.ButtonClick(Sender: TObject);
    BEGIN
      showmessage(Format('你点的是%d', [(sender AS Tbutton).tag]))
    END;END.