I’m using Delphi 2006 and psvActiveScript.
Example:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,
ObjComAuto, ComObj, psvActiveScript;
type
TForm1 = class(TForm)
btnExecute: TButton;
procedure btnExecuteClick(Sender: TObject);
procedure ASWError(Sender: TObject; Line, Pos: Integer; ASrc, ADescription: String);
end;
var
Form1: TForm1;
ASW: TpsvActiveScriptWindow;
implementation
{$R *.DFM}
type
{$METHODINFO ON}
TMySriptableClass = class(TObjectDispatch)
public
constructor Create;
procedure Alert(msg: string);
// THIS OR SOMETHING SIMILAR NOT POSSIBLE? **********************
function FnWithVarNumOfArgs(const args: array of string): string;
// **************************************************************
end;
{$METHODINFO OFF}
constructor TMySriptableClass.Create;
begin inherited Create(Self, False); end;
procedure TMySriptableClass.Alert(msg: string);
begin ShowMessage(msg); end;
function TMySriptableClass.FnWithVarNumOfArgs(const args: array of string): string;
begin Result := 'OK'; end;
procedure TForm1.btnExecuteClick(Sender: TObject);
var
MyObj: TMySriptableClass;
begin
ASW := TpsvActiveScriptWindow.Create(self);
ASW.ScriptLanguage := 'JScript';
ASW.OnError := ASWError;
MyObj := TMySriptableClass.Create;
ASW.AddNamedItem('MyObj', MyObj);
try
ASW.Execute(
'MyObj.Alert("Warning: Here comes Error");'+
'MyObj.FnWithVarNumOfArgs("1","2","3")'
);
finally
ASW.Free;
end;
end;
procedure TForm1.ASWError(Sender: TObject; Line, Pos: Integer; ASrc, ADescription: String);
begin Showmessage(ADescription + ': ' + ASrc); end;
end.
1 Answer