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

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

问题描述

Delphi 是否为表单创建(或更一般地说,表单生命周期事件)提供某种事件或钩子?

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

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

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?

我知道有一些选项涉及引入基表单类或自定义表单创建过程,但是对于已经有很多表单的现有应用程序来说,很高兴拥有"一个非侵入性的选项来添加类似于 cross 的内容- 消除面向切面编程 (AOP) 中的关注点.

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;

推荐答案

目前我能想到的最接近的选项是每次触发的 Screen.OnActiveFormChange 事件当前活动形式发生变化.但这对于您的需求来说可能为时已晚.

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天全站免登陆