释放动态创建的TApdComPort + TApdDataPaceet 有内存泄露?(200)

  • 主题发起人 主题发起人 Dv
  • 开始时间 开始时间
D

Dv

Unregistered / Unconfirmed
GUEST, unregistred user!
XP sp2, D7, APRO 4.06, FastMM 4.78应用程序动态创建TApdComPort,TApdDataPacket.在TApdDataPacket.OnTimeOut事件中释放TApdComPort,TApdDataPacket.FastMM4提示有内存泄露.代码是要在超时一定次数后释放创建的对象.//==========================================================var I: Integer; FComPort: TApdComPort; FDataPacket: TApdDataPacket;...procedure CreateCOMOjbect;begin FComPort := TApdComPort.Create(nil); with FComPort do try //定义端口属性; .... FDataPacket := TApdDataPacket.Create(nil); with FDataPacket do try ComPort := FComPort; //定义通讯规则 .... //超时设置 TimeOut := 10; //触发事件 OnTimeOut := PacketTimeOut; except FDataPacket.Free; end; except FComPort.Free; end; I := 0;end;procedure PacketTimeOut(Sender: TObject);begin Inc(I); if I > 2 then begin FDataPacket.Free; FComPort.Free; end else FDataPacket.Enabled := True;end;//==========================================================也试过APRO 4.07,故障依然出现.不知原因何在?请高人赐教.谢谢!
 
是我自己错了!Warning: Never explicitly free a component within one of its own event handlers or the event handler of a component it owns or contains. For example, don’t free a button, or the form that owns the button, in its OnClick event handler.
 
可惜了你的分。
 
接受答案了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
547
import
I
I
回复
0
查看
491
import
I
后退
顶部