unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, uPSComponent,
uPSC_std, uPSR_std,
uPSC_Classes, uPSR_classes,
uPSC_Controls, uPSR_Controls,
uPSC_Forms, uPSR_Forms,
uPSRuntime;
type
{ TForm1 }
TForm1 = class(TForm)
private
FScripter: TPSScript;
procedure Compilar(Sender: TPSScript);
procedure ExecImport(Sender: TObject; se: TPSExec; x: TPSRuntimeClassImporter);
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
constructor TForm1.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
FScripter := TPSScript.Create(Self);
FScripter.OnCompile := @Compilar;
FScripter.OnExecImport := @ExecImport;
FScripter.Script.Add( 'procedure fechar(Sender: TObject; var CloseAction: TCloseAction); ' );
FScripter.Script.Add( 'begin ' );
FScripter.Script.Add( ' Showmessage( ''Vou fechar'' ); ' );
FScripter.Script.Add( 'end; ' );
FScripter.Script.Add( ' ' );
FScripter.Script.Add( 'procedure MyProgram; ' );
FScripter.Script.Add( 'var F: TForm; ' );
FScripter.Script.Add( 'begin ' );
FScripter.Script.Add( ' F := TForm.Create(NIL); ' );
FScripter.Script.Add( ' try ' );
FScripter.Script.Add( ' F.Caption := ''Form created and displayed by the script !!'' ' );
FScripter.Script.Add( ' F.Width := 800; ' );
FScripter.Script.Add( ' F.Position := poScreenCenter; ' );
FScripter.Script.Add( ' F.OnClose := @fechar; ' );
FScripter.Script.Add( ' F.ShowModal; ' );
FScripter.Script.Add( ' finally ' );
FScripter.Script.Add( ' F.Free; ' );
FScripter.Script.Add( ' end; ' );
FScripter.Script.Add( 'end; ' );
FScripter.Script.Add( ' ' );
FScripter.Script.Add( 'begin ' );
FScripter.Script.Add( ' MyProgram; ' );
FScripter.Script.Add( 'end. ' );
if FScripter.Compile then begin
if not FScripter.Execute then begin
ShowMessage( 'Não executou' );
end;
end else begin
ShowMessage( FScripter.CompilerMessages[0].MessageToString );
end;
end;
destructor TForm1.Destroy;
begin
FScripter.Free;
inherited Destroy;
end;
procedure TForm1.Compilar(Sender: TPSScript);
begin
SIRegister_Std(Sender.Comp);
SIRegister_Classes(Sender.Comp,true);
SIRegister_Controls(Sender.Comp);
SIRegister_Forms(Sender.Comp);
Sender.AddFunction( @ShowMessage, 'procedure ShowMessage( const aMsg: String );');
end;
procedure TForm1.ExecImport(Sender: TObject; se: TPSExec;
x: TPSRuntimeClassImporter);
begin
RIRegister_Std(x);
RIRegister_Classes(x,true);
RIRegister_Controls(x);
RIRegister_Forms(x);
end;
end.