-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathArcHRScriptPax.pas
142 lines (123 loc) · 4.04 KB
/
ArcHRScriptPax.pas
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
unit ArcHRScriptPax;
interface
uses Classes, SysUtils, Types, ArcHTMLReporter, ArcTagParser, ArcHRScript,
PaxScripter, PaxJavaScript, PaxPascal, PaxC, PaxBasic, IMP_Classes,
IMP_StrUtils, IMP_DateUtils, IMP_IniFiles, IMP_SysUtils, IMP_Math, IMP_Registry;
type
TPaxLang = (pxPascal, pxC, pxJavascript, pxBasic);
TPaxLangs = set of TPaxLang;
THTMLReportPaxScript = class(THTMLReportScriptBase)
private
FLanguages: TPaxLangs;
FScripter : TPaxScripter;
FPaxBasic : TPaxBasic;
FPaxC : TPaxC;
FPaxJavascript : TPaxJavaScript;
FPaxPascal : TPaxPascal;
FModules : TStringList;
OutText : string;
protected
procedure ClearModules; virtual;
procedure ScriptPrint(Sender: TPaxScripter; const S: String);
public
procedure InitHandler(ASender: TObject); override;
procedure OnShowError(Sender : TPaxScripter);
procedure TagHandler(ASender: TObject; ATag: TTagItem; var AReplaceText: string; var IsTag: Boolean); override;
public
destructor Destroy; override;
constructor Create(AOwner: TComponent); override;
published
property Languages : TPaxLangs read FLanguages write FLanguages default [pxPascal, pxC, pxJavascript, pxBasic];
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Arcana', [THTMLReportPaxScript]);
end;
{ THTMLReportPaxScript }
procedure THTMLReportPaxScript.ClearModules;
var
i: Integer;
begin
for i := 0 to FModules.Count - 1 do
TStringList(FModules.Objects[i]).Free;
FModules.Clear;
end;
constructor THTMLReportPaxScript.Create(AOwner: TComponent);
begin
inherited;
FModules := TStringList.Create;
FLanguages := [pxPascal, pxC, pxJavascript, pxBasic];
FScripter := TPaxScripter.Create(Self);
FScripter.OnPrint := ScriptPrint;
FScripter.OnShowError := OnShowError;
FPaxBasic := TPaxBasic.Create(Self);
FPaxC := TPaxC.Create(Self);
FPaxJavascript := TPaxJavaScript.Create(Self);
FPaxPascal := TPaxPascal.Create(Self);
end;
destructor THTMLReportPaxScript.Destroy;
begin
ClearModules;
FModules.Free;
inherited;
end;
procedure THTMLReportPaxScript.InitHandler(ASender: TObject);
begin
inherited;
ClearModules;
FScripter.ResetScripter;
end;
procedure THTMLReportPaxScript.OnShowError(Sender: TPaxScripter);
var
sMsg : string;
begin
sMsg := 'Script Compilation Error'#13#10#13#10+
'Module: '+FScripter.ErrorModuleName+#13#10#13#10+
'Line: '+IntToStr(FScripter.ErrorLine)+' Char: '+IntToStr(FScripter.ErrorPos)+#13#10#13#10+
'Message: '+FScripter.ErrorDescription;
if not ReportError(sMsg) then
raise EAbort.Create(FScripter.ErrorDescription);
end;
procedure THTMLReportPaxScript.ScriptPrint(Sender: TPaxScripter; const S: String);
begin
OutText := s;
end;
procedure THTMLReportPaxScript.TagHandler(ASender: TObject; ATag: TTagItem;
var AReplaceText: string; var IsTag: Boolean);
var
sLang, sModule, sScript : string;
idx : integer;
i: Integer;
begin
inherited;
OutText := '';
sLang := ATag.FindParamValue('language');
sModule := ATag.FindParamValue('module');
sScript := ATag.FindParamValue('src');
if sLang='' then
sLang := 'javascript';
if sModule ='' then
sModule := 'main'+sLang;
idx := FModules.IndexOfName(sModule);
if idx < 0 then
begin
idx := FModules.AddObject(sModule+'='+sLang, TStringList.Create);
TStringList(FModules.Objects[idx]).Add('uses SysUtils, Classes, StrUtils, DateUtils, Math, IniFiles, Registry;');
end;
TStringList(FModules.Objects[idx]).Add(sScript);
//sModule := sModule+IntToStr(Integer(ATag));
FScripter.ResetScripter;
FScripter.RegisterVariable('Text','string',@OutText);
for i := 0 to FModules.Count - 1 do
begin
FScripter.AddModule(FModules.Names[i],'pax'+FModules.ValueFromIndex[i]);
FScripter.AddCode(FModules.Names[i],TStringList(FModules.Objects[i]).Text);
end;
//FScripter.Compile;
FScripter.Run;
AReplaceText := OutText;
IsTag := False;
end;
end.