unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure DoSelect(Sender: TObject);
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.DoSelect(Sender: TObject);
begin
  // 你的处理
end;procedure TForm1.FormCreate(Sender: TObject);
begin
  ComboBox1.OnSelect := DoSelect;
end;end.

解决方案 »

  1.   

    ComboBox1.OnSelect := DoSelect;
      

  2.   

    我用free方法释放的时候老是要出错,那怎么做能释放掉新建的控件,从form上把删它删掉,谢谢了
      

  3.   

    不错,就
       ComboBox1.OnSelect := DoSelect;
         可以解决响应事件的问题。你释放控件的时候,即使你调用了Free方法,它指向的地址还存在,所以表面看来它还存在,跟踪调试的时候就可以发现,实际上这段内存已经被释放掉了。不用担心,不会造成内存泄露。
      

  4.   

    我以前也是在动态创建控件释放资源的时候出现了错误,所以我建议你这样试试。
    var 
      MyComboBox:TComboBox;
    begin
      ...........
      MyComboBox:=TComboBox.Create(Self);
      //让MyComboBox的拥有者为其所在的窗体,这样当窗体释放时,这个控件也就
     //释放了,程序中就不要用手工释放了。这样我想就没有错误了。
    end;
    另外,你也可以把MyComboBox.Free写在异常处理之中
      

  5.   

    bit1.FreeInstance;
    bit1.FreeOnRelease;
    bit1.FreeNotification();
    和bit1.Free这几个Free有什么不一样啊