Delphi - AddMethod
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
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
INCOMPATIBILITY EXTENDED EXTENDED
Seems that extended in fastscript and extended in delphi XE2 are not the same !!!!
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