Delphi Web Script(DWScript)将脚本方法链接到外部控件事件 [英] Delphi Web Script (DWScript) link a script method to an external control event

查看:1297
本文介绍了Delphi Web Script(DWScript)将脚本方法链接到外部控件事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道DWScript是否支持使用脚本方法作为Delphi表单上的控件的事件处理程序。例如,我想将TButton OnClick事件链接到脚本中存在的方法。

I'm wondering if DWScript supports using a script method as an event handler for a control on a Delphi form. For example I want to link a TButton OnClick event to a method that exists in script.

我可以通过调用GetProcMethod返回一个TMethod对象,通过RemObjects Delphi脚本引擎执行此操作。然后我使用SetMethodProp将脚本方法分配给按钮的OnClick事件。

I am able to do this with the RemObjects Delphi script engine by calling GetProcMethod which returns a TMethod object. I then use SetMethodProp to assign the script method to the OnClick event of a button.

procedure LinkMethod(SourceMethodName: String; Instance: TObject; ScriptMethodName: String);
var
  ScriptMethod: TMethod;
begin
  ScriptMethod := ScriptEngine.GetProcMethod(ScripMethodName);

  SetMethodProp(Instance, SourceMethodName, ScriptMethod);
end;

我想在DWScript中执行此操作,而不是Rem对象脚本引擎,因为它会做一些其他的东西我需要使用RemObjects。

I would like to do this in DWScript instead of the Rem objects script engine as it does some other stuff that I need.

推荐答案

这是最简单的使用方式,我需要做。

I decided to go with RemObjects instead. It was the easiest to use and does what I need.

这篇关于Delphi Web Script(DWScript)将脚本方法链接到外部控件事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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