One feature of FastScript + Delphi

    When developing one small project in Delphi using FastScript, they encountered one non-obvious feature.
    I hope someone found the feature will be useful and save development time.

    The project used ZeosLib, and the following construction was written to create an additional layer:

    type
      TMyQuery = TZQuery;
    


    That is, the TMyQuery type was declared as a synonym for TZQuery, and then objects of this type were created in the program.
    Everything went well until we began to bind to the FastScript project to remove part of the functionality into blocks that could (and needed) be changed without recompiling the project.

    Inside scripts, the use of database queries was implied.
    Therefore, in accordance with the documentation, when initializing the script engine, we added our class to it:

    TFunctions = class(TfsRTTIModule)
      private
        ...
      public
        constructor Create(AScript: TfsScript); override;
      end;
    constructor TFunctions.Create(AScript: TfsScript);
    begin
      inherited Create(AScript);
      with AScript do
      begin
        ...
        AddClass(TMyQuery ,'TDataSet');
         ...
      end;
    end;
    


    When trying to declare a variable of our type inside the script, they received a message:

    Были обнаружены следующие ошибки: Ошибка в скрипте 10:4: Неизвестный тип: 'TMyQuery'

    At the same time, other classes imported into the script worked quietly. Yes, and on the line itself:

       AddClass(TMyQuery ,'TDataSet'); 
    


    neither at compile time, nor at run time there were no errors and warnings.
    As a result of a couple of hours of searching for the problem, it turned out that FastScript simply could not correctly import classes that are described as synonymous with another class.

    After changing the type description to:

    type
      TMyQuery = class(TZQuery);
    


    (that is, TMyQuery is now not a synonym, but the heir to TZQuery)
    everything fell into place.

    Software Version: Delphi 2010, FastScript 4. Not tested in other versions and combinations.

    Also popular now: