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.
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.
ComboBox1.OnSelect := DoSelect;
可以解决响应事件的问题。你释放控件的时候,即使你调用了Free方法,它指向的地址还存在,所以表面看来它还存在,跟踪调试的时候就可以发现,实际上这段内存已经被释放掉了。不用担心,不会造成内存泄露。
var
MyComboBox:TComboBox;
begin
...........
MyComboBox:=TComboBox.Create(Self);
//让MyComboBox的拥有者为其所在的窗体,这样当窗体释放时,这个控件也就
//释放了,程序中就不要用手工释放了。这样我想就没有错误了。
end;
另外,你也可以把MyComboBox.Free写在异常处理之中
bit1.FreeOnRelease;
bit1.FreeNotification();
和bit1.Free这几个Free有什么不一样啊