Hello
I'm going to show you how you can write own scripter (pascal interpreter).
at first you need to get RemObject Pascal Interpreter
You can find it here
www.remobjects.com
Download
Ok now just install this package :P
Open new project in Delphi and put at form memmo and 2x buttons
and Pascal Scripter component
Now you need to add some lines to uses
Code:
uses
... uPSRuntime,uPSCompiler;
Ok so lets set event onClick for button1 named "Compile"
this is a full code for button1 click:
Code:
procedure TForm1.Button1Click(Sender: TObject);
procedure OutputMessages;
var
l: Longint;
b: Boolean;
begin
b := False;
for l := 0 to PSScript1.CompilerMessageCount - 1 do
begin
showmessage('Compiler: '+ PSScript1.CompilerErrorToStr(l));
if (not b) and (PSScript1.CompilerMessages[l] is TIFPSPascalCompilerError) then
begin
b := True;
Memo1.SelStart := PSScript1.CompilerMessages[l].Pos;
end;
end;
end;
begin
PSScript1.Script.Assign(Memo1.Lines);
if PSScript1.Compile then
begin
OutputMessages;
showmessage('Compiled succesfully');
if not PSScript1.Execute then
begin
Memo1.SelStart := PSScript1.ExecErrorPosition;
showmessage(PSScript1.ExecErrorToString +' at '+Inttostr(PSScript1.ExecErrorProcNo)+'.'+Inttostr(PSScript1.ExecErrorByteCodePosition));
end;
end else
begin
OutputMessages;
showmessage('Compiling failed');
end;
end;
from now you can compile your code (F9), write in memmo
and click "Compile"
You will see a messagebox with message "Compiled succesfully"
Great!
Now I will show how to add your own functions and procedures to scripter
First you need to create function or procedure that you will use in you scripter for example ShowMSG(s:String);
Code:
Procedure ShowMSG(s:String);
begin
showmessage(s);
end;
Double click at OnCompile event in PSScript1
Code:
procedure TForm1.PSScript1Compile(Sender: TPSScript);
begin
Sender.AddFunction(@ShowMSG,'procedure ShowMSG(s:string);');
end;
compile (F9) and write in memmo this code:
Code:
Begin
showMSG('lol');
end.
You will see a message that code was sucessfull compiled and next message "lol"
You can try to compile something more difficult like
Code:
var
a:byte;
b:byte;
c:byte;
begin
a:=5;
b:=4;
for c:=0 to 2 do
begin
ShowMSG(inttostr(a+b));
end;
end.
This is all in this lesson :P in next one I will show you how to import own classes into scripter