Delphi - AddMethod

edited July 2013 in FastScript
Hi,

I have my DELPHI function:

function TFSFunctions.Round (roundValue : Double; iRound: integer): Double;
begin
result := RoundToDecimals (roundValue,iRound);
end;


So I want to add this function to script object:


procedure TFSFunctions.AddFSFunctions(fsScriptObj : TfsScript);
begin

fsScriptObj.AddMethod('function MYROUND(roundValue : Double; iRound: integer): Double', CallMethod);
end;


And then I have implemented CallMethod:

function TFSFunctions.CallMethod(Instance: TObject; ClassType: TClass; const MethodName: String; var Params: Variant): Variant;
begin
if MethodName = 'MYROUND' then
begin
result := MyRoundFunction(Params[0], Params[1]);
end;
end;


Compile and seems to work... BUT when I compile this script below I get an error:

fsScriptObj.Lines.Add('var RESULT :Double;');
fsScriptObj.Lines.Add('begin');
fsScriptObj.Lines.Add('RESULT := (1100*(2000-0)*7850/1000000000000);');
fsScriptObj.Lines.Add('RESULT := MYROUND(RESULT, 2);');
fsScriptObj.Lines.Add('end.');

fsScriptObj.Parent := fsGlobalUnit;
fsScriptObj.SyntaxType := 'PascalScript';

fsScriptObj.Compile; // GETTING ERROR

I get an error during run time. Incompatible type EXTENDED and DOUBLE.
I cannot see where is the extended variable in my code. I want to use ONLY DOUBLE.

What's wrong?

I also change the function name from ROUND to MYROUND but doesn't work....

Thanks in advance

Comments

  • edited 12:31PM
    Also I have changed ALL TYPES TO EXTENDED and I have the error

    INCOMPATIBILITY EXTENDED EXTENDED

    Seems that extended in fastscript and extended in delphi XE2 are not the same !!!!
  • edited July 2013
    I found the problem in FASTSCRIPT in this function:

    function AssignCompatible(Var1, Var2: TfsCustomVariable; Script: TfsScript): Boolean;
    var
    t1, t2: TfsTypeRec;
    begin
    t1.Typ := Var1.Typ;
    t1.TypeName := Var1.TypeName;
    t2.Typ := Var2.Typ;
    t2.TypeName := Var2.TypeName;

    [...]
    end;

    Var1.Typ is equal to fvtClass
    Var1.TypeName is equal to DOUBLE

    Var2.Typ is equal to fvtFloat
    Var2.TypeName is equal to DOUBLE

    Can I have an explanation WHY FS recognized fvtClass instead of fvtFloat????

    Thanks in advance

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.