如何在运行时(Delphi / Windows)中在程序内添加代码? [英] How to add code inside a program in runtime (Delphi/Windows)?

查看:83
本文介绍了如何在运行时(Delphi / Windows)中在程序内添加代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Windows XP / Delphi7。我需要在正在运行的程序内添加一些过程(或功能),并且我不想在完成后再次重新编译它。

I'm working on Windows XP/Delphi 7. I need to add some procedures (or functions) inside a program that is running, and I do not want to re-compile it once again after I finished it.

我只有一个具有5个功能的主机应用程序,可以发送不同类型的警报,但是还有其他新的警报类型,因此我必须执行新功能来发送这些警报,但我不应该重新构建主机应用程序。我有一个名为TAlarmManager的类,该类将调用这些函数。

I just have a host application with 5 functions to send different types of alarms, but there are other new alarm types, so I have to do new functions to send those alarms, but I should not re-build the host application. I have a class named TAlarmManager that it's invoked calling those functions.

也许是插件??可以,但是如何插入新功能???教程,手册,书籍等。用于学习此内容或有关如何执行此操作的任何建议?

Maybe a plugin?? OK, but how can I "insert" new functions??? Tutorial, manual, book, etc.. for learning about this, or any advice on how to do this???

我已经研究了插件(我是全新的主题),但是没有人谈论向主机应用程序添加功能。在我看来,插件是从自身添加功能的,我的意思是,它们是使用自我代码开发的,可以做某些事情,而不是将代码添加到主机应用程序中。。。我该怎么做??

I have studied plugins (I'm totally new on this theme), but no one "talks" about adding functions to a host application. It seems to me that plugins add functionality from itself, I mean, they have been developed with self code to do something, not to "add" code to the host application... How can I do this??

推荐答案

对于技术方面:Delphi IDE是如何做到的?

For the technical side: How does the Delphi IDE do it? That would be the first place for me to look.

要了解插件,您必须了解您无法添加新功能。您可以,但是由于旧代码不知道如何调用,因此不会调用它们。

To understand plugins, you must understand that you can't add new functions. You could but since the old code doesn't know how to call it, they wouldn't be called.

因此,您要做的是添加注册或插件的启动功能。该启动函数将数据结构作为参数进行检查或扩展。在您的情况下,这将是警报列表。警报始终工作相同(我猜是这样),因此它可以添加其他警报。

So what you do is you add a "register" or "start" function to your plugin. That start function gets a data structure as parameter which it can examine or extend. In your case, that would be the list of alarms. Alarms always work the same (my guess), so it can add additional alarms.

注册所有插件后,主代码将仅在警报列表上移动并在它们各自上调用标准警报功能。它不再关心每个警报的来源和实际作用。

The main code will then, after registering all plugins, just walk over the list of alarms and invoke the standard alarm function on each of them. It no longer cares where each alarm comes from and what it really does.

此处的关键:您需要定义双方都订阅的接口。主要代码调用接口函数,而您的插件代码实现了它们。

The key here: You need to define an interface which both sides subscribe to. The main code calls the interface functions and your plugin code implements them.

这篇关于如何在运行时(Delphi / Windows)中在程序内添加代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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