如何使用ScriptControl并加载Unicode res文件?

时间:2022-09-01 11:39:56

How do I convert this VB6 code to Delphi?

如何将此VB6代码转换为Delphi?

strConv(a, vbUnicode)

and

Private cScript As New ScriptControl
cScript.Language = "Javascript"
cScript.Reset
cScript.AddCode StrConv(LoadResData(101, "RSADATA"), vbUnicode)
cScript.Run("createRsaKey", data1 , data2)

1 个解决方案

#1


3  

First this: I agree with @DavidHeffernan: please (pretty please) search for a way to perform the logic in Delphi.

首先:我同意@DavidHeffernan:请(非常请)搜索在Delphi中执行逻辑的方法。

Follow these steps:

跟着这些步骤:

  • Find the Import Type Library menu function, depending on the Delphi version it may be under different top menu's (typically Components or Tools), or have a different name (Import ActiveX, Import COM object...)
  • 找到导入类型库菜单功能,取决于Delphi版本,它可能位于不同的*菜单(通常是组件或工具),或具有不同的名称(导入ActiveX,导入COM对象...)

  • From the list of known type libraries, select "Microsoft Script Control", the highest version in the list (but chances are it's still just version 1.0)
  • 从已知类型库的列表中,选择“Microsoft Script Control”,列表中的最高版本(但它可能仍然只是版本1.0)

  • Create the wrapper unit
  • 创建包装器单元

Then use an instance of the TScriptControl object, perhaps like this:

然后使用TScriptControl对象的实例,可能是这样的:

var
  sc:TScriptControl;
  sa:PSafeArray;
  code:WideString;
  rs:TResourceStream;
begin
  rs:=TResourceStream.Create(HInstance,'RSADATA',MakeIntResource(101));
  try
    SetLength(code,rs.Size div 2);
    rs.Read(PWideChar(code)^,rs.Size);
  finally
    rs.Free;
  end;

  sc:=TScriptControl.Create(nil);
  try
    sc.Language:='Javascript';
    sc.Reset;
    sc.AddCode(code);
    sa:=PSafeArray(TVarData(VarArrayOf([data1,data2])).VArray);
    sc.Run('createRsaKey',sa);
  finally
    sc.Free;
  end;
end;

#1


3  

First this: I agree with @DavidHeffernan: please (pretty please) search for a way to perform the logic in Delphi.

首先:我同意@DavidHeffernan:请(非常请)搜索在Delphi中执行逻辑的方法。

Follow these steps:

跟着这些步骤:

  • Find the Import Type Library menu function, depending on the Delphi version it may be under different top menu's (typically Components or Tools), or have a different name (Import ActiveX, Import COM object...)
  • 找到导入类型库菜单功能,取决于Delphi版本,它可能位于不同的*菜单(通常是组件或工具),或具有不同的名称(导入ActiveX,导入COM对象...)

  • From the list of known type libraries, select "Microsoft Script Control", the highest version in the list (but chances are it's still just version 1.0)
  • 从已知类型库的列表中,选择“Microsoft Script Control”,列表中的最高版本(但它可能仍然只是版本1.0)

  • Create the wrapper unit
  • 创建包装器单元

Then use an instance of the TScriptControl object, perhaps like this:

然后使用TScriptControl对象的实例,可能是这样的:

var
  sc:TScriptControl;
  sa:PSafeArray;
  code:WideString;
  rs:TResourceStream;
begin
  rs:=TResourceStream.Create(HInstance,'RSADATA',MakeIntResource(101));
  try
    SetLength(code,rs.Size div 2);
    rs.Read(PWideChar(code)^,rs.Size);
  finally
    rs.Free;
  end;

  sc:=TScriptControl.Create(nil);
  try
    sc.Language:='Javascript';
    sc.Reset;
    sc.AddCode(code);
    sa:=PSafeArray(TVarData(VarArrayOf([data1,data2])).VArray);
    sc.Run('createRsaKey',sa);
  finally
    sc.Free;
  end;
end;