TPaxScripter Demo. Separate compilation.


var
  S: TPaxScripter;
  LangPascal: TPaxPascal;
  LangBasic: TPaxBasic;
  LangC: TPaxC;
begin
/////// CREATE COMPILED MODULES //////////////////////

  S := TPaxScripter.Create(nil);

  LangPascal := TPaxPascal.Create(nil);
  LangC := TPaxC.Create(nil);
  LangBasic := TPaxBasic.Create(nil);
  S.RegisterLanguage(LangPascal);
  S.RegisterLanguage(LangC);
  S.RegisterLanguage(LangBasic);

  S.AddModule('0', LangPascal.LanguageName);
  S.AddCode('0', 'const A = 17;');
  S.AddCode('0', 'const B = 10 + A;');

  S.AddModule('1', LangC.LanguageName);
  S.AddCode('1', 'void P(x){ print x; }');

  S.AddModule('2', LangC.LanguageName);
  S.AddCode('2', 'using Classes, Forms;');
  S.AddCode('2', 'class MyForm: TForm {');
  S.AddCode('2', '  void MyForm(TComponent Owner) {');
  S.AddCode('2', '     this = base.Create(Owner);');
  S.AddCode('2', '     Caption = "MyForm"; ');
  S.AddCode('2', '  }');
  S.AddCode('2', '}');

  S.Compile;

  S.SaveModuleToFile('0', 'u0.bin');
  S.SaveModuleToFile('1', 'u1.bin');
  S.SaveModuleToFile('2', 'u2.bin');

  S.Free;

  LangPascal.Free;
  LangC.Free;

/////// USE COMPILED MODULES /////////////////////////

  S := TPaxScripter.Create(nil);

  LangBasic := TPaxBasic.Create(nil);
  S.RegisterLanguage(LangBasic);

  // add a source code module
  S.AddModule('one', 'paxBasic');
  S.AddCode('one', 'Dim F As MyForm');
  S.AddCode('one', 'F = New MyForm(NULL)');
  S.AddCode('one', 'F.Show()');
  S.AddCode('one', 'print A');
  S.AddCode('one', 'print B');
  S.AddCode('one', 'P(300)');

  // add compiled modules in a random order
  S.LoadModuleFromFile('1', 'u1.bin');
  S.LoadModuleFromFile('0', 'u0.bin');
  S.LoadModuleFromFile('2', 'u2.bin');

  S.Run;

  S.Free;
  LangBasic.Free;


Copyright © 1999-2006 VIRT Laboratory. All rights reserved.