重构 Delphi 6 事件处理程序属性的工具/实用程序?
我有一个在我的应用程序代码库(即多个应用程序)中广泛使用的组件。我想更改常用的事件处理程序属性之一。我需要一个工具/实用程序来遍历 Delphi 6 表单源文件 (DFM + PAS),并对表单上组件实例的当前定义的事件处理程序进行搜索和替换。
例如。假设我在组件上有一个事件处理程序属性,当前定义为:
property eventHandler1: TOldEventHandlerProc read FOnEvent write FOnEvent;
其中 TOldEventHandlerProc 定义为:
TOldEventHandlerProc = procedure(oneParm: string) of object;
我想将 TOldEventHandlerProc 更改为:
TOldEventHandlerProc = procedure(oneParm: string; twoParm: integer) of object;
我希望实用程序检查 Form 的 DFM/PAS 文件对的内容并查找 FOnEvent 的所有实例定义并根据 TOldEventHandlerProc 的新定义将旧参数列表替换为新参数列表。例如,给定一个名为 MyForm1 的表单,其中包含一个名为 MyComp1 的组件实例,您将获得以下 IDE 为事件处理程序生成的声明:
TMyForm1 = class(TForm)
// IDE created event handler stubs.
procedure MyComp1OnEvent(oneParm: string);
事件处理程序的主体声明为:
procedure TMyForm1.MYCom1OnEvent(oneParm: string);
该实用程序需要查找 OnEvent( 的每个实例) ) 处理程序并替换事件处理程序的标头声明和事件处理程序的主体声明,并交换参数列表,结果为:
TMyForm1 = class(TForm)
// IDE created event handler stubs.
procedure MyComp1OnEvent(oneParm: string; twoParm: integer);
事件处理程序的主体声明为:
procedure TMyForm1.MYCom1OnEvent(oneParm: string; twoParm: integer);
如果我找不到这样的工具,我'我自己会写一篇又快又脏的文章,但我我想我会问一下是否可以节省一些时间。有人知道这样的重构工具吗?
I have a component that is used widely throughout my application code base (i.e. - multiple applications). I want to change one of the commonly used event handler properties. I need a tool/utility that would go through a Delphi 6 form source file (DFM + PAS) and do a search and replace for the currently defined event handlers for instances of the component on the form.
For example. Suppose I have an event handler property on the component currently defined as:
property eventHandler1: TOldEventHandlerProc read FOnEvent write FOnEvent;
Where TOldEventHandlerProc is defined as:
TOldEventHandlerProc = procedure(oneParm: string) of object;
I want to change TOldEventHandlerProc to:
TOldEventHandlerProc = procedure(oneParm: string; twoParm: integer) of object;
I would want the utility to examine the contents of a Form's DFM/PAS file pair and find all instances of FOnEvent that are defined and swap out the old parameter list for the new parameter list, based on the new definition of TOldEventHandlerProc. For example, given a form named MyForm1 with an instance of the component named MyComp1 you would have the following IDE generated declaration for the event handler:
TMyForm1 = class(TForm)
// IDE created event handler stubs.
procedure MyComp1OnEvent(oneParm: string);
with the body of the event handler declared as:
procedure TMyForm1.MYCom1OnEvent(oneParm: string);
The utility would need to find each instance of OnEvent() handler and substitute the header declaration for the event handler and the body declaration for the event handler and swap the parameter lists with the result being:
TMyForm1 = class(TForm)
// IDE created event handler stubs.
procedure MyComp1OnEvent(oneParm: string; twoParm: integer);
with the body of the event handler declared as:
procedure TMyForm1.MYCom1OnEvent(oneParm: string; twoParm: integer);
If I can't find such a tool I'll write a quick and dirty one myself but I figured I'd ask to see if I could save myself some time. Does anyone know of such a refactoring tool?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最近的 Delphi 版本提供了重构功能。
您可以使用其中之一轻松重构代码,并最终修复每个 DFM 以确保 Delphi 6 兼容性。
Refactoring feature is available in recent Delphi version.
You can easily refactor your code using one of them and eventually fix every DFM to ensure Delphi 6 compatibility.