pascalscript/Samples/RemObjects SDK Client/fMain.pas
carlokok 666c4e5069 rename
git-svn-id: http://code.remobjects.com/svn/pascalscript@152 5c9d2617-0215-0410-a2ee-e80e04d1c6d8
2009-06-10 08:26:53 +00:00

175 lines
4.7 KiB
ObjectPascal

unit fMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, uPSComponent, uPSCompiler, Menus, uPSRuntime,
uROPSServerLink, uPSComponent_Default;
type
TForm1 = class(TForm)
Memo1: TMemo;
Memo2: TMemo;
Splitter1: TSplitter;
PSScript: TPSScript;
PS3DllPlugin: TPSDllPlugin;
MainMenu1: TMainMenu;
Program1: TMenuItem;
Compile1: TMenuItem;
PS3RemObjectsPlugin1: TPSRemObjectsSdkPlugin;
OpenDialog1: TOpenDialog;
OpenDialog2: TOpenDialog;
N1: TMenuItem;
OpenScript1: TMenuItem;
OpenRODL1: TMenuItem;
PSImport_Classes1: TPSImport_Classes;
PSImport_DateUtils1: TPSImport_DateUtils;
procedure IFPS3ClassesPlugin1CompImport(Sender: TObject;
x: TPSPascalCompiler);
procedure IFPS3ClassesPlugin1ExecImport(Sender: TObject; Exec: TPSExec;
x: TPSRuntimeClassImporter);
procedure PSScriptCompile(Sender: TPSScript);
procedure Compile1Click(Sender: TObject);
procedure PSScriptExecute(Sender: TPSScript);
procedure OpenRODL1Click(Sender: TObject);
procedure OpenScript1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses
uPSR_std,
uPSC_std,
uPSR_stdctrls,
uPSC_stdctrls,
uPSR_forms,
uPSC_forms,
uPSC_graphics,
uPSC_controls,
uPSC_classes,
uPSR_graphics,
uPSR_controls,
uPSR_classes;
{$R *.DFM}
procedure TForm1.IFPS3ClassesPlugin1CompImport(Sender: TObject;
x: TIFPSPascalcompiler);
begin
SIRegister_Std(x);
SIRegister_Classes(x, true);
SIRegister_Graphics(x, true);
SIRegister_Controls(x);
SIRegister_stdctrls(x);
SIRegister_Forms(x);
end;
procedure TForm1.IFPS3ClassesPlugin1ExecImport(Sender: TObject; Exec: TIFPSExec;
x: TIFPSRuntimeClassImporter);
begin
RIRegister_Std(x);
RIRegister_Classes(x, True);
RIRegister_Graphics(x, True);
RIRegister_Controls(x);
RIRegister_stdctrls(x);
RIRegister_Forms(x);
end;
function ImportTest(S1: string; s2: Longint; s3: Byte; s4: word; var s5: string): string;
begin
Result := s1 + ' ' + IntToStr(s2) + ' ' + IntToStr(s3) + ' ' + IntToStr(s4) + ' - OK!';
S5 := s5 + ' '+ result + ' - OK2!';
end;
procedure MyWriteln(const s: string);
begin
Form1.Memo2.Lines.Add(s);
end;
function MyReadln(const question: string): string;
begin
Result := InputBox(question, '', '');
end;
procedure TForm1.PSScriptCompile(Sender: TPSScript);
begin
Sender.AddFunction(@MyWriteln, 'procedure Writeln(s: string);');
Sender.AddFunction(@MyReadln, 'function Readln(question: string): string;');
Sender.AddFunction(@ImportTest, 'function ImportTest(S1: string; s2: Longint; s3: Byte; s4: word; var s5: string): string;');
Sender.AddRegisteredVariable('Application', 'TApplication');
Sender.AddRegisteredVariable('Self', 'TForm');
Sender.AddRegisteredVariable('Memo1', 'TMemo');
Sender.AddRegisteredVariable('Memo2', 'TMemo');
end;
procedure TForm1.Compile1Click(Sender: TObject);
procedure OutputMessages;
var
l: Longint;
b: Boolean;
begin
b := False;
for l := 0 to PSScript.CompilerMessageCount - 1 do
begin
Memo2.Lines.Add('Compiler: '+ PSScript.CompilerErrorToStr(l));
if (not b) and (PSScript.CompilerMessages[l] is TIFPSPascalCompilerError) then
begin
b := True;
Memo1.SelStart := PSScript.CompilerMessages[l].Pos;
end;
end;
end;
begin
Memo2.Lines.Clear;
PSScript.Script.Assign(Memo1.Lines);
Memo2.Lines.Add('Compiling');
if PSScript.Compile then
begin
OutputMessages;
Memo2.Lines.Add('Compiled succesfully');
if not PSScript.Execute then
begin
Memo1.SelStart := PSScript.ExecErrorPosition;
Memo2.Lines.Add(PSScript.ExecErrorToString +' at '+Inttostr(PSScript.ExecErrorProcNo)+'.'+Inttostr(PSScript.ExecErrorByteCodePosition));
end else Memo2.Lines.Add('Succesfully executed');
end else
begin
OutputMessages;
Memo2.Lines.Add('Compiling failed');
end;
end;
procedure TForm1.PSScriptExecute(Sender: TPSScript);
begin
PSScript.SetVarToInstance('APPLICATION', Application);
PSScript.SetVarToInstance('SELF', Self);
PSScript.SetVarToInstance('MEMO1', Memo1);
PSScript.SetVarToInstance('MEMO2', Memo2);
end;
procedure TForm1.OpenRODL1Click(Sender: TObject);
begin
if OpenDialog2.Execute then
begin
PS3RemObjectsPlugin1.RODLLoadFromFile(OpenDialog2.FileName);
end;
end;
procedure TForm1.OpenScript1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
Memo1.Lines.LoadFromFile(OpenDialog1.FileName);
end;
end;
end.