Forum > Packages and Libraries
Upon the power of the Pascal script
(1/1)
tr_escape:
You can create very powerful external code on you executable file with by pascal script...
Remobjects factory created a freeware component that name is pascal script and this component can be usable to lazarus and delphi.
For setup right bottom of this web page :O
http://www.remobjects.com/trials.aspx#free
Directly link is:
http://www.remobjects.com/download.aspx?file=RemObjects%20Pascal%20Script%20for%20Delphi%20-%203.0.55.957.exe.url.txt
After installation you can find source files in this directory and lazarus packet lpk “C:\Program Files\RemObjects Software\Pascal Script for Delphi\Source”
My advice is move this directory to lazarus component directory and change the name to pascalsript.
For component install you should open pascalscript.lpk and compile to lazarus.
Another issue is you should change syntax of lazarus compiler's to delphi.
http://mehmetulukaya.files.wordpress.com/2011/12/compiler_settings.jpg?w=500&h=415
After compiling lazarus you can see Pascal script tab on lazarus component palette.In this packet you can find some sample codes but we can create a simple code with pascal script.
Create a new project and put a memo , button and label component on form.
http://mehmetulukaya.files.wordpress.com/2011/12/test_project.jpg?w=1024&h=616
Firstly we will sure of our programs is it working?
--- Code: ---procedure TForm1.ExecuteClick(Sender: TObject);
begin
PSScript1.Script := memScript.Lines;
if PSScript1.Compile then
begin
if PSScript1.Execute then
lblStatus.Caption := 'Executed...';
end
else
begin
lblStatus.Caption := 'Error...';
end;
end;
--- End code ---
http://mehmetulukaya.files.wordpress.com/2011/12/test_project_run_00.jpg?w=500&h=289
We are ready for create all of code...
--- Code: ---unit main;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, uPSComponent, uPSCompiler, uPSRuntime,
uPSR_std,
uPSC_std,
uPSR_stdctrls,
uPSC_stdctrls,
uPSR_forms,
uPSC_forms,
uPSC_graphics,
uPSC_controls,
uPSC_classes,
uPSR_graphics,
uPSR_controls,
uPSR_classes;
type
{ TForm1 }
TForm1 = class(TForm)
Execute: TButton;
Label1: TLabel;
lblStatus: TLabel;
memScript: TMemo;
PSScript1: TPSScript;
procedure ExecuteClick(Sender: TObject);
procedure PSScript1Compile(Sender: TPSScript);
procedure PSScript1CompImport(Sender: TObject; x: TPSPascalCompiler);
procedure PSScript1ExecImport(Sender: TObject; se: TPSExec;
x: TPSRuntimeClassImporter);
procedure PSScript1Execute(Sender: TPSScript);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{ TForm1 }
procedure TForm1.ExecuteClick(Sender: TObject);
begin
PSScript1.Script := memScript.Lines;
if PSScript1.Compile then
begin
if PSScript1.Execute then
lblStatus.Caption := 'Executed...';
end
else
begin
lblStatus.Caption := 'Error...';
end;
end;
procedure TForm1.PSScript1Compile(Sender: TPSScript);
begin
Sender.AddRegisteredVariable('Application', 'TApplication');
Sender.AddRegisteredVariable('Self', 'TForm');
end;
procedure TForm1.PSScript1CompImport(Sender: TObject; x: TPSPascalCompiler);
begin
SIRegister_Std(x);
SIRegister_Classes(x, true);
SIRegister_Graphics(x, true);
SIRegister_Controls(x);
SIRegister_stdctrls(x);
SIRegister_Forms(x);
end;
procedure TForm1.PSScript1ExecImport(Sender: TObject; se: TPSExec;
x: TPSRuntimeClassImporter);
begin
RIRegister_Std(x);
RIRegister_Classes(x, True);
RIRegister_Graphics(x, True);
RIRegister_Controls(x);
RIRegister_stdctrls(x);
RIRegister_Forms(x);
end;
procedure TForm1.PSScript1Execute(Sender: TPSScript);
begin
PSScript1.SetVarToInstance('APPLICATION', Application);
PSScript1.SetVarToInstance('SELF', Self);
end;
initialization
{$I main.lrs}
end.
--- End code ---
Runtime the program:
http://mehmetulukaya.files.wordpress.com/2011/12/test_project_run_01.jpg?w=500&h=298
If you want to rich to label component and other object in script you should recognize you objects to pascal script before compile and execute.
Orginal article:
http://mehmetulukaya.wordpress.com/2011/12/19/scriptlerin-gucu-adina/
Navigation
[0] Message Index