-1

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)
Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
aurora
  • 11
  • 1
  • First of you need to decide how to execute the JavaScript in your Delphi program? What are your intentions? – David Heffernan Feb 18 '15 at 07:30
  • Perhaps the easiest way forward would be to scrub out the JavaScript and code it all in Delphi. Don't feel that you have to translate every line of code verbatim. Feel free to choose better ways to solve problems. – David Heffernan Feb 18 '15 at 08:17

1 Answers1

3

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;
Stijn Sanders
  • 35,982
  • 11
  • 45
  • 67