Delphi是否为表单创建通知提供事件处理程序? [英] Does Delphi offer an event handler for form creation notifications?

查看:276
本文介绍了Delphi是否为表单创建通知提供事件处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Delphi为表单创建提供某种事件或钩子(或者更常见的是生成周期事件)?



所以如果代码中的某个表单是创建并显示(模态或非模态,动态地或在通常的应用程序starup阶段),Delphi调用一个事件处理程序,允许在显示之前记录/分析/修改表单?



我知道有一些选项涉及引入一个基础表单类或一个自定义表单创建过程,但对于已经有很多形式的现有应用程序来说,这将是很好的非侵入式选项来添加类似的东西在面向方面的程序设计(AOP)中交叉的关注。



例如,如果我有一些代码用于使用统计信息跟踪注入额外的事件处理程序,我可以简单地添加这个功能对于每个窗体,开发人员不必更改应用程序代码,只需添加类似于

的代码

  ... 
Application.O nNewForm:= MyNewFormCreated;
...

程序TMyApp.MyNewFormCreated(发件人:TCustomForm);
begin
//迭代组件,并使用新的表单
...
end;


解决方案

最近我可以想到的选项可以满足您需要的是每次当前活动表单更改时触发的 Screen.OnActiveFormChange 事件。但是,在您的需求过程中可能太晚了。


Does Delphi provide some kind of event or hook for form creation (or more generally, form lifecycle events)?

So that if somewhere in the code a form is created and shown (modal or non-modal, dynamically or in the usual app starup stage), Delphi calls an event handler which allows to log / analyse / modify the form before it is shown?

I know there are options which involve introducing a base form class or a custom form creation procedure, but for existing applications which already have many forms it would be 'nice to have' a non-intrusive option to add something similar to cross-cutting concerns in Aspect oriented programming (AOP).

For example, if I had some code for usage statistics tracking which injects additional event handlers, I could simply add this functionality for every form, developers would not have to change the application code, only add code similar to this

...
   Application.OnNewForm := MyNewFormCreated;
...

procedure TMyApp.MyNewFormCreated(Sender: TCustomForm);
begin
  // iterate over components and do other stuff with the new form
  ...
end;

解决方案

The closest option I can think of at the moment that could fit your need is the Screen.OnActiveFormChange event that is triggered every time the current active form changes. But that might be too late in the process for your needs.

这篇关于Delphi是否为表单创建通知提供事件处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆