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'.

Comments

  • edited 6:30AM
    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 6:30AM
    Peta wrote: »
    Both your functions are Test1.
    ...

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

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.