Conceptual error in the script engine

edited February 2019 in FastReport VCL
Due to the incorrect implementation of caching of parameters in functions exported in FastScript, the further use of these functions is potentially dangerous because obtaining unpredictable results.

For example, we declare two functions in the script.
First function:
function Test1(aValue : boolean = false) : string;
begin
  result := iif(aValue, 'True', 'False');                                     
end;
The second function is the twin of the first:
function Test2(aValue : boolean = false) : string;
begin
  result := iif(aValue, 'True', 'False');                                     
end;
Then call them:
  ShowMessage(Test1(True) + ' ' + Test2(False));

We get the result: 'True True' instead of the expected 'True False'.
fr6.png 14.6K

Comments

  • edited 10:15AM
    Both your functions are Test1. Below is a complete script.
    And I think it's better to open a ticket than to write in this forum.
    function Test1(aValue : boolean) : string;
    begin
      result := iif(aValue, 'True', 'False');                                    
    end;
    
    function Test2(aValue : boolean) : string;
    begin
      result := iif(aValue, 'True', 'False');                                    
    end;    
    
    begin
      ShowMessage(Test1(True) + ' ' + Test2(False));  
    end.
    
  • edited 10:15AM
    Peta wrote: »
    Both your functions are Test1.
    ...

    Thanks for the remark, I corrected the code in the original message.

Leave a Comment