简体   繁体   English

DWS可以从样本单元调用功能吗?

[英]May DWS calling functions from sample unit?

May DWS calling functions from sample unit? DWS可以从样本单元调用功能吗? For example: 例如:

FExecution.Info.Func['Test.ClickProc'].Call(AParams); (This is not working)

FExecution - IdwsProgramExecution; FExecution-IdwsProgramExecution;

Function declared in Script code: 脚本代码中声明的函数:

unit Test;
Uses UTestUnit;
procedure TestFunc(LParam: string);
begin
  ShowMessage(LParam);
end;
procedure ClickProc(Sender: TObject);
begin
  ShowMessage('DWS');
end;
var  S: TStringList;
var  btn: TButton;
begin
  btn := TButton.Create(MainForm);
  btn.OnClick := ClickProc;
  btn.Parent(MainForm);
end.

ClickProc in this example. 在此示例中为ClickProc。

I don't think it can be done. 我认为这是不可能的。

The symbol lookup in the call to Info.Func[] doesn't resolve the name into a unit scope and an identifier but instead does a simple lookup for a symbol named "Test.ClickProc". Info.Func[]的调用中的符号查找不会将名称解析为单元作用域和标识符,而是对名为“ Test.ClickProc”的符号进行简单查找。 However since the ClickProc procedure symbol is named "ClickProc" the lookup doesn't find it. 但是,由于ClickProc过程符号被命名为“ ClickProc”,因此无法找到它。

I thought that maybe it would be possible to find the procedure symbol manually via the symbol tables... 我认为也许可以通过符号表手动找到过程符号...

var
  FExecution: IdwsProgramExecution;
  UnitSymbol: TUnitMainSymbol;
  FuncSymbol: TFuncSymbol;
  Info: IInfo;
begin
  ...
  UnitSymbol := FExecution.Prog.UnitMains.Find('Test');
  FuncSymbol := UnitSymbol.Table.FindSymbol('ClickProc', cvPublic) as TFuncSymbol; // Returns nil :-(
  Info := FExecution.Info.FuncBySym[FuncSymbol];
  Info.Call;
  ...

... but after consulting the "documentation" ( read: studying the source, stepping through with a debugger and much trial and error ) I've come to the conclusion that it cannot be done reliably at this time. ...但是查阅了“文档”之后(请阅读:研究源代码,逐步调试并进行多次尝试和错误 ),我得出的结论是,目前无法可靠地完成此操作。 It is possible to find the "ClickProc" symbol in one of the many symbol tables but I've not been able to find a reliable way to qualify the symbol with a unit name/symbol. 可以发现在许多符号表中的一个“ClickProc”的象征,但我已经无法找到一个可靠的方法来与资格的单位名称/符号的符号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM