Skip to content

Commit

Permalink
Better compatibility with scripts created using Delphi
Browse files Browse the repository at this point in the history
Replace multiple uses instances.
Ignore UITypes standard library in scripts.
  • Loading branch information
zilav committed Jan 15, 2018
1 parent d51c2a0 commit 9f0a3c3
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions frmViewMain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -5574,16 +5574,20 @@ procedure TfrmMain.ApplyScript(aScript: string);
try
regexp.Subject := aScript;
regexp.RegEx := '^\s*uses\s+(.+?);';
regexp.Options := [preCaseLess, preMultiLine];
if regexp.Match then begin
regexp.Options := [preCaseLess, preSingleLine, preMultiLine];
while regexp.MatchAgain do begin
i := regexp.MatchedOffset;
s := regexp.MatchedText;
s := StringReplace(s, 'system.', '', [rfReplaceAll, rfIgnoreCase]);
s := StringReplace(s, 'vcl.', '', [rfReplaceAll, rfIgnoreCase]);
s := StringReplace(s, 'winapi.', '', [rfReplaceAll, rfIgnoreCase]);
s := StringReplace(s, 'data.', '', [rfReplaceAll, rfIgnoreCase]);
s := StringReplace(s, 'web.', '', [rfReplaceAll, rfIgnoreCase]);
if s <> regexp.MatchedText then
aScript := StringReplace(aScript, regexp.MatchedText, s, []);
if s <> regexp.MatchedText then begin
aScript := Copy(aScript, 1, i-1) + s + Copy(aScript, i + Length(regexp.MatchedText), Length(aScript));
regexp.Subject := aScript;
end;
regexp.Start := i + Length(s);
end;
finally
regexp.Free;
Expand Down Expand Up @@ -14762,24 +14766,22 @@ function IsUnitCompiledIn(Module: HMODULE; const UnitName: string): Boolean;
procedure TfrmMain.JvInterpreterProgram1GetUnitSource(UnitName: string;
var Source: string; var Done: Boolean);
var
sl: TStringList;
UnitFile: string;
begin
// return empty unit source code if the standard one is used
if SameText(UnitName, 'xEditAPI') or IsUnitCompiledIn(HInstance, UnitName) then begin
if SameText(UnitName, 'xEditAPI') or SameText(UnitName, 'UITypes') or IsUnitCompiledIn(HInstance, UnitName) then begin
Source := 'unit ' + UnitName + '; end.';
Done := True;
Exit;
end;

UnitFile := wbScriptsPath + UnitName + '.pas';
sl := TStringList.Create;
try
sl.LoadFromFile(UnitFile);
Source := sl.Text;
with TStringList.Create do try
LoadFromFile(UnitFile);
Source := Text;
Done := True;
finally
sl.Free;
Free;
end;
end;

Expand Down

0 comments on commit 9f0a3c3

Please sign in to comment.