在您的 delphi 应用程序中托管 WSH(VBScript、JavaScript)?
我正在寻找从我的 Delphi 应用程序执行用户提供的脚本。
是否可以在我的应用程序中托管 Windows 脚本宿主引擎并为其提供要执行的脚本? 或者,有更好的方法来解决这个问题吗?
PS 我不是在寻找第三方组件。
I'm looking to execute user supplied scripts from my Delphi application.
Is it possible to host the Windows Script Host engine in my application and supply it with scripts to execute? Or, is there a better way to approach this problem?
P.S I'm not looking for third-party components.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是完全可能的,并且有大量代码展示了如何做到这一点。 查看:http://www.torry.net/pages.php?id=280
This is entirely possible and there is plenty of code out there that shows how to do this. Check out: http://www.torry.net/pages.php?id=280
几年前,Allen Bauer 发表了一篇关于使用活动脚本的博客文章。 它深入探讨了其背后的理论,并链接到 Code Central 上的代码,该代码支持 VBScript 和 JavaScript,无需第三方组件。
Allen Bauer made a blog post about using Active Scripting a few years back. It goes into the theory behind it and links to code on Code Central which supports VBScript and JavaScript, no third party components necessary.
这是我从这个 C++ 问题转换而来的完整代码示例:
如何加载& 从 C++ 中调用 VBScript 函数?
您需要 IActiveScript 等接口,其定义如下:
这是转换后的示例代码:
只需运行
TestActiveScriptingOuter
方法即可。 您应该从 VBScript 获得一个 MsgBox,并且在调试器中您可以看到如何计算表达式并将其传递给Res
变体。此示例没有展示如何传入脚本可以与之交互的 COM 对象。 这应该可以通过
IActiveScript.AddNamedItem
和IActiveScriptSite.GetItemInfo
实现。此外,代码中没有错误检查,您应该在生产中使用它之前添加它!
Here is a complete code sample which I converted from this C++ question:
How to load & call a VBScript function from within C++?
You need the IActiveScript, etc. interfaces which are defined like this:
Here is the converted example code:
Just run the
TestActiveScriptingOuter
method. You should get a MsgBox from VBScript and in the debugger you can see how expressions are evaluated and passed to theRes
variant.What this example does not show is how to pass in COM objects that the script can interact with. This should be possbile via
IActiveScript.AddNamedItem
andIActiveScriptSite.GetItemInfo
.Also there is no error checking in the code which you should add before using it in production!
您不需要任何第三方组件即可使用 Windows Script Host。 我们使用它已有十年,并围绕它构建了一个庞大的 ERP 系统,其中包含超过 100 万行 VBScript 源代码。
您应该使用 Windows 脚本控制来告知 Windows 脚本宿主或仅通过已知接口直接连接。
You don't need any thrid party components for using Windows Script Host. We use it for ten years and have built a huge ERP system around it with more than 1 million of source code lines in VBScript.
You should use Windows Script Control in order to tell to Windows Script Host or just connect directly through known interfaces.