home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 November / Chip_2002-11_cd1.bin / zkuste / delphi / kompon / d456 / CAJSCRPT.ZIP / ifps3 / demo_comp / Unit1.pas < prev   
Pascal/Delphi Source File  |  2002-07-08  |  4KB  |  151 lines

  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   ExtCtrls, StdCtrls, IFPS3CompExec, Menus;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Memo1: TMemo;
  12.     Memo2: TMemo;
  13.     Splitter1: TSplitter;
  14.     IFPS3CompExec1: TIFPS3CompExec;
  15.     IFPS3DllPlugin1: TIFPS3DllPlugin;
  16.     IFPS3ClassesPlugin1: TIFPS3ClassesPlugin;
  17.     MainMenu1: TMainMenu;
  18.     Program1: TMenuItem;
  19.     Compile1: TMenuItem;
  20.     procedure IFPS3ClassesPlugin1CompImport(Sender: TObject;
  21.       x: TIFPSCompileTimeClassesImporter);
  22.     procedure IFPS3ClassesPlugin1ExecImport(Sender: TObject;
  23.       x: TIFPSRuntimeClassImporter);
  24.     procedure IFPS3CompExec1Compile(Sender: TIFPS3CompExec);
  25.     procedure Compile1Click(Sender: TObject);
  26.     procedure IFPS3CompExec1Execute(Sender: TIFPS3CompExec);
  27.   private
  28.     { Private declarations }
  29.   public
  30.     { Public declarations }
  31.   end;
  32.  
  33. var
  34.   Form1: TForm1;
  35.  
  36. implementation
  37. uses
  38.   ifpiir_std,
  39.   ifpii_std,
  40.   ifpiir_stdctrls,
  41.   ifpii_stdctrls,
  42.   ifpiir_forms,
  43.   ifpii_forms,
  44.   ifpii_graphics,
  45.   ifpii_controls,
  46.   ifpii_classes,
  47.   ifpiir_graphics,
  48.   ifpiir_controls,
  49.   ifpiir_classes,
  50.   ifpscomp
  51.   ;
  52.  
  53. {$R *.DFM}
  54.  
  55. procedure TForm1.IFPS3ClassesPlugin1CompImport(Sender: TObject;
  56.   x: TIFPSCompileTimeClassesImporter);
  57. begin
  58.   SIRegister_Std(x);
  59.   SIRegister_Classes(x);
  60.   SIRegister_Graphics(x);
  61.   SIRegister_Controls(x);
  62.   SIRegister_stdctrls(x);
  63.   SIRegister_Forms(x);
  64. end;
  65.  
  66. procedure TForm1.IFPS3ClassesPlugin1ExecImport(Sender: TObject;
  67.   x: TIFPSRuntimeClassImporter);
  68. begin
  69.   RIRegister_Std(x);
  70.   RIRegister_Classes(x);
  71.   RIRegister_Graphics(x);
  72.   RIRegister_Controls(x);
  73.   RIRegister_stdctrls(x);
  74.   RIRegister_Forms(x);
  75. end;
  76.  
  77. function ImportTest(S1: string; s2: Longint; s3: Byte; s4: word; var s5: string): string;
  78. begin
  79.   Result := s1 + ' ' + IntToStr(s2) + ' ' + IntToStr(s3) + ' ' + IntToStr(s4) + ' - OK!';
  80.   S5 := s5 + ' '+ result + ' -   OK2!';
  81. end;
  82.  
  83. procedure MyWriteln(const s: string);
  84. begin
  85.   Form1.Memo2.Lines.Add(s);
  86. end;
  87.  
  88. function MyReadln(const question: string): string;
  89. begin
  90.   Result := InputBox(question, '', '');
  91. end;
  92.  
  93. procedure TForm1.IFPS3CompExec1Compile(Sender: TIFPS3CompExec);
  94. begin
  95.   Sender.AddFunction(@MyWriteln, 'procedure Writeln(s: string);');
  96.   Sender.AddFunction(@MyReadln, 'function Readln(question: string): string;');
  97.   Sender.AddFunction(@ImportTest, 'function ImportTest(S1: string; s2: Longint; s3: Byte; s4: word; var s5: string): string;');
  98.   Sender.AddRegisteredVariable('Application', 'TApplication');
  99.   Sender.AddRegisteredVariable('Self', 'TForm');
  100.   Sender.AddRegisteredVariable('Memo1', 'TMemo');
  101.   Sender.AddRegisteredVariable('Memo2', 'TMemo');
  102. end;
  103.  
  104. procedure TForm1.Compile1Click(Sender: TObject);
  105.   procedure OutputMessages;
  106.   var
  107.     l: Longint;
  108.     b: Boolean;
  109.   begin
  110.     b := False;
  111.  
  112.     for l := 0 to IFPS3CompExec1.CompilerMessageCount - 1 do
  113.     begin
  114.       Memo2.Lines.Add('Compiler: '+ IFPS3CompExec1.CompilerErrorToStr(l));
  115.       if (not b) and (IFPS3CompExec1.CompilerMessages[l].MessageType = pterror) then
  116.       begin
  117.         b := True;
  118.         Memo1.SelStart := IFPS3CompExec1.CompilerMessages[l].Position;
  119.       end;
  120.     end;
  121.   end;
  122. begin
  123.   Memo2.Lines.Clear;
  124.   IFPS3CompExec1.Script.Assign(Memo1.Lines);
  125.   Memo2.Lines.Add('Compiling');
  126.   if IFPS3CompExec1.Compile then
  127.   begin
  128.     OutputMessages;
  129.     Memo2.Lines.Add('Compiled succesfully');
  130.     if not IFPS3CompExec1.Execute then
  131.     begin
  132.       Memo1.SelStart := IFPS3CompExec1.ExecErrorPosition;
  133.       Memo2.Lines.Add(IFPS3CompExec1.ExecErrorToString +' at '+Inttostr(IFPS3CompExec1.ExecErrorProcNo)+'.'+Inttostr(IFPS3CompExec1.ExecErrorByteCodePosition));
  134.     end else Memo2.Lines.Add('Succesfully executed');
  135.   end else
  136.   begin
  137.     OutputMessages;
  138.     Memo2.Lines.Add('Compiling failed');
  139.   end;
  140. end;
  141.  
  142. procedure TForm1.IFPS3CompExec1Execute(Sender: TIFPS3CompExec);
  143. begin
  144.   IFPS3ClassesPlugin1.SetVarToInstance('APPLICATION', Application);
  145.   IFPS3ClassesPlugin1.SetVarToInstance('SELF', Self);
  146.   IFPS3ClassesPlugin1.SetVarToInstance('MEMO1', Memo1);
  147.   IFPS3ClassesPlugin1.SetVarToInstance('MEMO2', Memo2);
  148. end;
  149.  
  150. end.
  151.