我想使用dwscript进行Web编程(生成动态内容).我想知道apache web服务器是否有任何模块?或者我如何基于dwscript运行自己的Web服务器?
好吧,我对DWScript完全不熟悉.现在我对它的能力非常着迷,但是虽然我在附带的wiki和问题/答案中阅读了所有页面,但是在从Delphi调用函数之后我仍然无法找到提取结果的方法:
func := m_dwsExec.info.Func[funcname];
func.call(params);
Run Code Online (Sandbox Code Playgroud)
然后我被困住了:exec.result.toString什么也没给我.只要我看到我没有Result在EXEC对象,这就是为什么清除从脚本项目时,堆叠的结果已经被删除和丢失.请告诉我这项简单任务的正确方法是什么?
我正在尝试从dwscript内部执行此代码(这是一个最小的样本,以便使用CreateOleObject)
function GetFileVersion(const FileName: string): string;
var
V : OleVariant;
begin
V := CreateOleObject('Scripting.FileSystemObject');
Result := V.GetFileVersion(FileName);
end;
Run Code Online (Sandbox Code Playgroud)
到目前为止我试过这个
{$APPTYPE CONSOLE}
{$R *.res}
uses
SysUtils,
ComObj,
ActiveX,
dwsComp,
dwsCompiler,
dwsExprs,
dwsCoreExprs;
procedure Execute;
var
LScript: TDelphiWebScript;
LUnit: TdwsUnit;
LProg: IdwsProgram;
LExec: IdwsProgramExecution;
begin
LScript := TDelphiWebScript.Create(NIL);
LUnit := TdwsUnit.Create(NIL);
try
LUnit.UnitName := 'Foo';
LUnit.Script := LScript;
// compile a simple script
LProg := LScript.Compile(
'function GetFileVersion(const FileName: string): string;'+sLineBreak+
'var'+sLineBreak+
' V : Variant;'+sLineBreak+
'begin'+sLineBreak+
' V := CreateOleObject(''Scripting.FileSystemObject'');'+sLineBreak+
' …Run Code Online (Sandbox Code Playgroud) 我正在尝试用dwscript创建一个模态表单.我使用ExposeRtti注册表单,然后执行脚本,但在Script.Compile期间它在"堆栈溢出"时失败.有没有人有这个错误的解决方案.
我当然希望我不必手动注册所有TForm属性和函数,就像我们必须使用remobjects PascalScript一样,在这个时代它会让我们难看,就像避免那样......
dwscript可以这样做,还是形式超出了dwscript的范围(在这个阶段?)?
procedure TMainForm.Button1Click(Sender: TObject);
var AdwsProgramExecution: IdwsProgramExecution;
ADelphiWebScript: TDelphiWebScript;
AdwsProgram: IdwsProgram;
AdwsUnit: TdwsUnit;
begin
AdwsUnit := TdwsUnit.Create(nil);
ADelphiWebScript := TDelphiWebScript.Create(nil);
try
AdwsUnit.UnitName := 'ShowModalTest';
AdwsUnit.Script := ADelphiWebScript;
AdwsUnit.ExposeRTTI(TypeInfo(TObject)); //Otherwise GetOnAlignInsertBefore error when 'compiling'
AdwsUnit.ExposeRTTI(TypeInfo(TForm)); //Want t ocreate a form
AdwsProgram := ADelphiWebScript.Compile('procedure TestShowModal; begin TForm.Create(nil).ShowModal; end; end.'); //Stack overflow
if AdwsProgram.Msgs.Count = 0 then
begin
AdwsProgramExecution := AdwsProgram.Execute;
MEResult.Lines.Text := AdwsProgramExecution.Result.ToString;
end
else
MEResult.Lines.Text := AdwsProgram.Msgs.AsInfo;
finally
ADelphiWebScript.Free;
AdwsUnit.Free;
end;
end;
Run Code Online (Sandbox Code Playgroud) 我想知道DWScript是否支持使用脚本方法作为Delphi表单上的控件的事件处理程序.例如,我想将TButton OnClick事件链接到脚本中存在的方法.
我可以通过调用GetProcMethod来返回一个TMethod对象,使用RemObjects Delphi脚本引擎.然后,我使用SetMethodProp将脚本方法分配给按钮的OnClick事件.
procedure LinkMethod(SourceMethodName: String; Instance: TObject; ScriptMethodName: String);
var
ScriptMethod: TMethod;
begin
ScriptMethod := ScriptEngine.GetProcMethod(ScripMethodName);
SetMethodProp(Instance, SourceMethodName, ScriptMethod);
end;
Run Code Online (Sandbox Code Playgroud)
我想在DWScript而不是Rem对象脚本引擎中这样做,因为它做了我需要的其他一些东西.
我的delphi应用程序使用JvInterpreter(来自Jedi项目)运行脚本.
我使用的一个功能是表达式的运行时评估.
脚本示例:
[...]
ShowMessage(X_SomeName);
[...]
Run Code Online (Sandbox Code Playgroud)
JvInterpreter不知道X_SomeName.当需要X_SomeName的值时,脚本编写器调用其OnGetValue-callback.这指向我处理的功能.在那里,我查找X_SomeName的值并返回它.然后JvInterpreter用我提供的值调用ShowMessage.
现在我考虑切换到DelphiWebScript,因为它有一个合适的调试接口,也应该比JvInterpreter更快.
问题:我没有找到任何明显的方法来实现JvInterpreter对其OnGetValue/OnSetValue函数的作用.
应该考虑X_SomeName(实际上,大多数情况下)是由宿主应用程序处理的变量.
有任何想法吗?
谢谢!
我的问题很简单。我有一个具有以下代码的 dwsUnit:
type
TPointCoord = record
X: Float;
Y: Float;
Z: Float;
end;
type
TMyClass = class
private
fPosition: TPointCoord;
function GetPosition: TPointCoord;
procedure SetPosition(Val: TPointCoord);
public
property Position: TPointCoord read GetPosition write SetPosition;
constructor Create;
end;
function TMyClass.GetPosition: TPointCoord;
begin
Result := fPosition;
end;
procedure TMyClass.SetPosition(Val: TPointCoord);
begin
fPosition := Val;
end;
constructor TMyClass.Create;
begin
inherited Create;
fPosition.X := 1;
fPosition.Y := 2;
fPosition.Z := 3;
end;
var
mc: TMyClass;
begin
mc := TMyClass.Create;
mc.Position.X := 2; //Syntax Error …Run Code Online (Sandbox Code Playgroud) 有一个运行DWS脚本的Delphi应用程序.Delphi应用程序向脚本公开一个对象实例,我们称之为"MyApplication".被暴露的对象有一个方法,其中一个参数是一个过程.
从根本上说,目标是让一个Delphi方法进行一些计算,并在回调程序说它完成时停止这个计算.回调过程在脚本内部.
我已经通过将回调函数的名称作为字符串传递来实现这一点.它工作得很好,除了在脚本编译时没有进行类型检查.我想传递一个实际的过程,以便脚本编译器可以在编译时捕获任何错误.
怎么做?
为了帮助读者理解我的意思,我展示了一些 - 不工作 - 代码:
首先是Delphi方面的简化版本:
Interface
type
TAppCheckProc = procedure (var Done : Boolean);
TMyApplication = class(TPersistent)
published
procedure Demo(CheckProc : TAppCheckProc);
end;
Implementation
TMyApplication.Demo(CheckProc : TAppCheckProc);
var
Done : Boolean;
begin
Done := FALSE;
while not Done do begin
// Some more code here...
CheckProc(Done);
end;
end;
Run Code Online (Sandbox Code Playgroud)
第二,在脚本方面我有这个(也简化):
procedure CheckProc(
var Done : Boolean);
var
Value : Integer;
begin
DigitalIO.DataIn(1, Value);
Done := (Value and 8) = 0;
end;
procedure …Run Code Online (Sandbox Code Playgroud) 我在安装DWSScript组件时遇到问题.我正在使用Delphi XE2,当我尝试编译dwsLibRuntime.dpk时,我收到一个错误(需要数组类型).我正在使用从项目的svn repo中提取的最新DWScript源代码.
我究竟做错了什么?
toStr:=TStringListCracker(sl).FList[i].FString; //produces error
System.MonitorExit(sl);
Run Code Online (Sandbox Code Playgroud) 我可以在Delphi XE5程序中使用DWScript类在Android和/或IO下运行并使脚本工作吗?
delphi ×10
dwscript ×10
delphi-xe2 ×1
delphi-xe5 ×1
events ×1
jedi ×1
scripting ×1
webserver ×1