How to create Record Types?

I need to be able to create a Record Type for my users to use in their scripts. But, I seem to be having problems getting the created Record Type to work. And there is pretty much nothing within the scripter code to tell me what I am missing to get it to work.

I have created a standard record type. Then I created a recordwrapper for it.  Then I created the constructor and objtorec function for it. But, when i test the use of the record type. I get the following error on the line to create the instance of the record:

Unit Unit1: Unknown identifier or variable is not declared: 'TTestRec'.
Source Position: 7,23.

(NOTE: I receive the same error when using the IDE Demo.)

At first I thought that it was something that I had missed. So I created a test unit with just the record and had the ImportTool give it a try. With the exception of referencing the Record from the original test unit, the ImportTool created the exact same code I had created. And when using the resulting ap_test library. I get the exact same error.

Here is the script used to test the record:
Test Script

uses
  test;

var
  TestRec: TTestRec;
begin
  TestRec := TTestRec.create;
end;


And here is the code used to create the record:
Test

Unit Test;

interface

type
    TTestRec = record
      XCoord: integer;
      YCoord: integer;
      Sample: string;
      SaveBMP: boolean;
      Filename: string;
    end;
    
implementation

end.


ap_Test As created by the ImportTool

{***************************************************************************}
{ This source code was generated automatically by                           }
{ Pas file import tool for Scripter Studio (Pro)                            }
{                                                                           }
{ Scripter Studio and Pas file import tool for Scripter Studio              }
{ written by TMS Software                                                   }
{            copyright c 1997 - 2010                                        }
{            Email : info@tmssoftware.com                                   }
{            Web : http://www.tmssoftware.com                               }
{***************************************************************************}
unit ap_Test;

interface

uses
  Test,
  System.Variants,
  atScript;

{$WARNINGS OFF}

type
  TatTestLibrary = class(TatScripterLibrary)
    procedure Init; override;
    class function LibraryName: string; override;
  end;



  TTestRecWrapper = class(TatRecordWrapper)
  private
    FXCoord: integer;
    FYCoord: integer;
    FSample: string;
    FSaveBMP: boolean;
    FFilename: string;
  public
    constructor Create(ARecord: TTestRec);
    function ObjToRec: TTestRec;
  published
    property XCoord: integer read FXCoord write FXCoord;
    property YCoord: integer read FYCoord write FYCoord;
    property Sample: string read FSample write FSample;
    property SaveBMP: boolean read FSaveBMP write FSaveBMP;
    property Filename: string read FFilename write FFilename;
  end;
  

implementation

constructor TTestRecWrapper.Create(ARecord: TTestRec);
begin
  inherited Create;
  FXCoord := ARecord.XCoord;
  FYCoord := ARecord.YCoord;
  FSample := ARecord.Sample;
  FSaveBMP := ARecord.SaveBMP;
  FFilename := ARecord.Filename;
end;

function TTestRecWrapper.ObjToRec: TTestRec;
begin
  result.XCoord := FXCoord;
  result.YCoord := FYCoord;
  result.Sample := FSample;
  result.SaveBMP := FSaveBMP;
  result.Filename := FFilename;
end;



procedure TatTestLibrary.Init;
begin
  With Scripter.DefineClass(ClassType) do
  begin
  end;
end;

class function TatTestLibrary.LibraryName: string;
begin
  result := 'Test';
end;

initialization
  RegisterScripterLibrary(TatTestLibrary, True);

{$WARNINGS ON}

end.


I am sure that there is something that needs to be added. But, none of the source comments in atScript.pas leads me to what that is.

You need to declare it in Init method:



Scripter.DefineClass(TTestRecWrapper);


and then use TTestRecWrapper.Create in your script.
But if you are using Delphi XE2 and newer, you can simply use


Scripter.DefineRecordByRtti(TTestRec);