当暴露一个宿主类并从中调用一个过程时,我得到了这个异常:
第一次机会例外,$7513C41F。异常类 ECompileError 带有消息“没有名称为“GetUnitCount”的可访问成员”。处理 Project23.exe (12832)
如何解决这个问题?我正在使用来自 SVN 的最新版本。
program DWScript_Test;
{$APPTYPE CONSOLE}
uses
SysUtils,
dwsComp,
dwsCompiler,
dwsExprs,
dwsSymbols;
type
TMyClass = class
function GetUnitCount: Integer; // It does indeed exist..
end;
type
TTest = class
DWS: TDelphiWebScript;
dwsUnit: TdwsUnit;
fStats: TMyClass;
prog: IdwsProgram;
exec: IdwsProgramExecution;
procedure ExposeInstancesAfterInitTable(Sender: TObject);
procedure Execute(aText: string);
end;
function TMyClass.GetUnitCount: Integer;
begin
Result := 4;
end;
procedure TTest.ExposeInstancesAfterInitTable(Sender: TObject);
begin
dwsUnit.ExposeInstanceToUnit('fStats', 'TMyClass', fStats);
end;
procedure TTest.Execute(aText: string);
begin
DWS := TDelphiWebScript.Create(nil);
dwsUnit := TdwsUnit.Create(nil);
dwsUnit.UnitName := 'Test';
try
fStats := TMyClass.Create;
dwsUnit.Script := DWS;
dwsUnit.ExposeClassToUnit(TMyClass, TObject);
dwsUnit.OnAfterInitUnitTable := ExposeInstancesAfterInitTable;
prog := DWS.Compile(aText);
if prog.Msgs.Count = 0 then
begin
exec := prog.Execute;
Writeln(exec.Result.ToString);
end
else
Writeln(prog.Msgs.AsInfo);
finally
dwsUnit.Free;
DWS.Free;
end;
Readln;
end;
begin
TTest.Create.Execute('PrintLn(IntToStr(fStats.GetUnitCount));');
end.