Beginner Question #1

Greetings,

I am just starting with TMS Scripter.

I want to execute a script that adds lines to a TMemo (let's call it Memo1)

What are the steps that I need to execute in Delphi prior to loading the Scripter, and then assume the following script:

var
 i : integer;
begin
  for i := 0 to 99 do
    begin
    frmMain.memo1.Lines.Add('Hello');
    end;

end;

then assume that this is my delphi code:

procedure TfrmMain.Button1Click(Sender: TObject);
var
    i    : integer;
    s1   : string;
begin

    Scripter.AddComponent(frmMain);

    Scripter.SourceCode.Clear;
    for i := 0 to fldmSQLSource.Lines.Count - 1 do
         begin
         s1 := fldmSQLSource.Lines;
         Scripter.SourceCode.Add(s1);
         end;
    Scripter.Execute;

end;

What am I doing wrong?

Many thanks,

Paul Gregory
You need to use AddForm instead of AddComponent, if you want the components in the form to be accessed as form properties:


   Scripter.AddForm(frmMain);


Also, you should make scripter aware of TMemo.Lines property, and also TStrings.Add property. If you use Delphi XE2 and up, the more straightforward way to do so is:


Scripter.DefineClassByRTTI(TStrings);
Scripter.DefineClassByRTTI(TMemo);


Alternatively, you can also simply add units ap_StdCtrls and ap_Classes to your uses clause, and add libraries to the script:


uses {...}, ap_Classes, ap_StdCtrls;


Scripter.AddLibrary(TatStdCtrlsLibrary);
Scripter.AddLibrary(TatClassesLibrary);


As a final option, you could simply try to define properties and methods manually using DefineMethod and DefineProp, as described here:

http://www.tmssoftware.biz/business/scripter/doc/web/callingmethods.html
http://www.tmssoftware.biz/business/scripter/doc/web/moremethodcallingexamples.html
http://www.tmssoftware.biz/business/scripter/doc/web/acessingnon-publishedpropert.html