How to use ScriptControl & load Unicode res file?

480 Views Asked by At

How do I convert this VB6 code to 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

There are 1 best solutions below

5
Stijn Sanders On

First this: I agree with @DavidHeffernan: please (pretty please) search for a way to perform the logic in 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...)
  • 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)
  • Create the wrapper unit

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

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;