1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
|
unit fMain;
interface
uses
Classes, QGraphics, QControls, QForms, QDialogs,
uPSCompiler, uPSRuntime, uPSUtils, QMenus, QTypes, QStdCtrls, QExtCtrls;
type
TMainForm = class(TForm)
Memo1: TMemo;
Memo2: TMemo;
Splitter1: TSplitter;
MainMenu1: TMainMenu;
Toosl1: TMenuItem;
Compile1: TMenuItem;
File1: TMenuItem;
Exit1: TMenuItem;
N1: TMenuItem;
SaveAs1: TMenuItem;
Save1: TMenuItem;
Open1: TMenuItem;
New1: TMenuItem;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
N2: TMenuItem;
Stop1: TMenuItem;
N3: TMenuItem;
CompileandDisassemble1: TMenuItem;
procedure Compile1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure New1Click(Sender: TObject);
procedure Open1Click(Sender: TObject);
procedure Save1Click(Sender: TObject);
procedure SaveAs1Click(Sender: TObject);
procedure Memo1Change(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Stop1Click(Sender: TObject);
procedure CompileandDisassemble1Click(Sender: TObject);
private
fn: string;
changed: Boolean;
function SaveTest: Boolean;
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
uses
fDwin, uPSDisassembly, uPSC_dll, uPSR_dll;
{$R *.dfm}
function MyOnUses(Sender: TIFPSPascalCompiler; const Name: string): Boolean;
begin
if Name = 'SYSTEM' then
begin
TIFPSPascalCompiler(Sender).AddFunction('procedure Writeln(s: string);');
TIFPSPascalCompiler(Sender).AddFunction('function Readln(question: string): string;');
Sender.AddConstantN('NaN', 'extended').SetExtended(0.0 / 0.0);
Sender.AddConstantN('Infinity', 'extended').SetExtended(1.0 / 0.0);
Sender.AddConstantN('NegInfinity', 'extended').SetExtended(1.0 / 0.0);
Sender.AddDelphiFunction('function ImportTest(S1: string; s2: Longint; s3: Byte; s4: word; var s5: string): string;');
Result := True;
end
else
begin
TIFPSPascalCompiler(Sender).MakeError('', ecUnknownIdentifier, '');
Result := False;
end;
end;
function MyWriteln(Caller: TIFPSExec; p: TPSExternalProcRec; Global, Stack: TIFPSStack): Boolean;
begin
MainForm.Memo2.Lines.Add(Stack.GetString(-1));
Result := True;
end;
function MyReadln(Caller: TIFPSExec; p: TPSExternalProcRec; Global, Stack: TIFPSStack): Boolean;
begin
Stack.SetString(-1,InputBox(MainForm.Caption, Stack.GetString(-2), ''));
Result := True;
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;
var
I: Integer;
procedure RunLine(Sender: TIFPSExec);
begin
i := (i + 1) mod 15;
if i = 0 then Application.ProcessMessages;
end;
function MyExportCheck(Sender: TIFPSPascalCompiler; Proc: TIFPSInternalProcedure; const ProcDecl: string): Boolean;
begin
Result := TRue;
end;
procedure TMainForm.Compile1Click(Sender: TObject);
var
x1: TIFPSPascalCompiler;
x2: TIFPSExec;
s: string;
procedure Outputtxt(const s: string);
begin
Memo2.Lines.Add(s);
end;
procedure OutputMsgs;
var
l: Longint;
b: Boolean;
begin
b := False;
for l := 0 to x1.MsgCount - 1 do
begin
Outputtxt(x1.Msg[l].MessageToString);
if (not b) and (x1.Msg[l] is TPSPascalCompilerError) then
begin
b := True;
Memo1.SelStart := X1.Msg[l].Pos;
end;
end;
end;
begin
if tag <> 0 then exit;
Memo2.Clear;
x1 := TIFPSPascalCompiler.Create;
x1.OnExportCheck := MyExportCheck;
x1.OnUses := MyOnUses;
x1.OnExternalProc := DllExternalProc;
if x1.Compile(Memo1.Text) then
begin
Outputtxt('Succesfully compiled');
OutputMsgs;
if not x1.GetOutput(s) then
begin
x1.Free;
Outputtxt('[Error] : Could not get data');
exit;
end;
x1.Free;
x2 := TIFPSExec.Create;
RegisterDLLRuntime(x2);
tag := longint(x2);
if sender <> nil then
x2.OnRunLine := RunLine;
x2.RegisterFunctionName('WRITELN', MyWriteln, nil, nil);
x2.RegisterFunctionName('READLN', MyReadln, nil, nil);
x2.RegisterDelphiFunction(@importtest, 'IMPORTTEST', cdRegister);
if not x2.LoadData(s) then begin
Outputtxt('[Error] : Could not load data');
x2.Free;
exit;
end;
x2.RunScript;
if x2.ExceptionCode <> ENoError then
Outputtxt('[Runtime Error] : ' + TIFErrorToString(x2.ExceptionCode, x2.ExceptionString) +
' in ' + IntToStr(x2.ExceptionProcNo) + ' at ' + IntToSTr(x2.ExceptionPos))
else
OutputTxt('Successfully executed');
tag := 0;
x2.Free;
end
else
begin
Outputtxt('Failed when compiling');
OutputMsgs;
x1.Free;
end;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
Caption := 'RemObjects Pascal Script';
fn := '';
changed := False;
Memo1.Lines.Text := 'Program ROTEST;'#13#10'Begin'#13#10'End.';
end;
procedure TMainForm.Exit1Click(Sender: TObject);
begin
Close;
end;
procedure TMainForm.New1Click(Sender: TObject);
begin
if not SaveTest then
exit;
Memo1.Lines.Text := 'Program ROTEST;'#13#10'Begin'#13#10'End.';
Memo2.Lines.Clear;
fn := '';
end;
function TMainForm.SaveTest: Boolean;
begin
if changed then
begin
case MessageDlg('File is not saved, save now?', mtWarning, mbYesNoCancel, 0) of
mrYes:
begin
Save1Click(nil);
Result := not changed;
end;
mrNo: Result := True;
else
Result := False;
end;
end
else
Result := True;
end;
procedure TMainForm.Open1Click(Sender: TObject);
begin
if not SaveTest then
exit;
if OpenDialog1.Execute then
begin
Memo1.Lines.LoadFromFile(OpenDialog1.FileName);
changed := False;
Memo2.Lines.Clear;
fn := OpenDialog1.FileName;
end;
end;
procedure TMainForm.Save1Click(Sender: TObject);
begin
if fn = '' then
begin
Saveas1Click(nil);
end
else
begin
Memo1.Lines.SaveToFile(fn);
changed := False;
end;
end;
procedure TMainForm.SaveAs1Click(Sender: TObject);
begin
SaveDialog1.FileName := '';
if SaveDialog1.Execute then
begin
fn := SaveDialog1.FileName;
Memo1.Lines.SaveToFile(fn);
changed := False;
end;
end;
procedure TMainForm.Memo1Change(Sender: TObject);
begin
changed := True;
end;
procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose := SaveTest;
end;
procedure TMainForm.Stop1Click(Sender: TObject);
begin
if tag <> 0 then
TIFPSExec(tag).Stop;
end;
procedure TMainForm.CompileandDisassemble1Click(Sender: TObject);
var
x1: TIFPSPascalCompiler;
s, s2: string;
procedure OutputMsgs;
var
l: Longint;
b: Boolean;
begin
b := False;
for l := 0 to x1.MsgCount - 1 do
begin
Memo2.Lines.Add(x1.Msg[l].MessageToString);
if (not b) and (x1.Msg[l] is TPSPascalCompilerError) then
begin
b := True;
Memo1.SelStart := X1.Msg[l].Pos;
end;
end;
end;
begin
if tag <> 0 then exit;
Memo2.Clear;
x1 := TIFPSPascalCompiler.Create;
x1.OnExternalProc := DllExternalProc;
x1.OnUses := MyOnUses;
if x1.Compile(Memo1.Text) then
begin
Memo2.Lines.Add('Succesfully compiled');
OutputMsgs;
if not x1.GetOutput(s) then
begin
x1.Free;
Memo2.Lines.Add('[Error] : Could not get data');
exit;
end;
x1.Free;
IFPS3DataToText(s, s2);
dwin.Memo1.Text := s2;
dwin.showmodal;
end
else
begin
Memo2.Lines.Add('Failed when compiling');
OutputMsgs;
x1.Free;
end;
end;
end.
|