以前就发现过这个问题,但一直没有在意。昨天一个窗体FORMSHOW执行了两次,对数据有影响,于是搜索了一下这个问题的答案。
Since your other thread finally gave your situation, it was very easy to find the problem:
AForm.Position := poMainFormCenter;
This calls Perform(CM_RECREATEWND, 0, 0); which will execute an immediate recreate of the form.
这种情况多发生在MDI的窗体中。
解决的办法:
如果你不能干掉AForm.Position语句,那么可以设置一个变量来记录执行次数。
var iFirstExecute:boolean;
formCreate{
iFirstExecute:=true;
}
formShow{
if not iFirstExecute then exit;
// code of do sth.
iFirstExecute:=false;
}
本文探讨了一个常见的MDI窗体编程问题——FORMSHOW事件被触发多次的情况及其解决方案。作者通过调整代码逻辑,引入一个布尔变量iFirstExecute来确保FORMSHOW中的关键代码仅被执行一次。
3350

被折叠的 条评论
为什么被折叠?



