diff --git a/components/chelper/chelper.lpk b/components/chelper/chelper.lpk
index 59c6a6f1c..0b40b585c 100644
--- a/components/chelper/chelper.lpk
+++ b/components/chelper/chelper.lpk
@@ -14,8 +14,8 @@
-
-
+
+
@@ -37,10 +37,6 @@
-
-
-
-
diff --git a/components/chelper/converteridesettings.pas b/components/chelper/converteridesettings.pas
index 473fd6b40..24c320140 100644
--- a/components/chelper/converteridesettings.pas
+++ b/components/chelper/converteridesettings.pas
@@ -75,6 +75,7 @@ begin
try
ini:=TIniFile.Create(FileName);
try
+ ini.WriteBool('Tool', 'UseExt', UseExtTool);
ini.WriteString('Tool', 'Exe', ExtTool);
ini.WriteString('Tool', 'DefineFile', DefineFile);
finally
@@ -91,6 +92,7 @@ begin
try
ini:=TIniFile.Create(FileName);
try
+ UseExtTool:=ini.ReadBool('Tool', 'UseExt', UseExtTool);
ExtTool:=ini.ReadString('Tool', 'Exe', ExtTool);
DefineFile:=ini.ReadString('Tool', 'DefineFile',DefineFile);
finally
diff --git a/components/chelper/cparsertypes.pas b/components/chelper/cparsertypes.pas
index c5eee8cd5..cd3eac6e9 100755
--- a/components/chelper/cparsertypes.pas
+++ b/components/chelper/cparsertypes.pas
@@ -20,6 +20,7 @@ unit cparsertypes;
interface
+
{$ifdef fpc}{$mode delphi}{$h+}{$endif}
uses
@@ -2077,5 +2078,4 @@ initialization
ParseNamePart:=@ParseCNamePart;
ParsePreproc:=@ParseDefPreproc;
-
end.
diff --git a/components/chelper/ctopasconvert.pas b/components/chelper/ctopasconvert.pas
index 5b14ccba3..533dba441 100644
--- a/components/chelper/ctopasconvert.pas
+++ b/components/chelper/ctopasconvert.pas
@@ -1680,6 +1680,5 @@ begin
Result:=Copy(Result, 1, length(Result)-1);
end;
-
end.
diff --git a/components/chelper/extconvdialog.lfm b/components/chelper/extconvdialog.lfm
index 41d281be9..35dd00c24 100644
--- a/components/chelper/extconvdialog.lfm
+++ b/components/chelper/extconvdialog.lfm
@@ -15,7 +15,7 @@ object CtoPasConfig: TCtoPasConfig
Top = 8
Width = 622
Anchors = [akTop, akLeft, akRight, akBottom]
- PageIndex = 0
+ PageIndex = 1
TabOrder = 0
object pageMain: TPage
Caption = 'Main'
@@ -191,23 +191,38 @@ object CtoPasConfig: TCtoPasConfig
ClientWidth = 616
ClientHeight = 382
object edtExtTool: TEdit
+ AnchorSideTop.Control = chkUseExternal
+ AnchorSideTop.Side = asrBottom
Left = 13
Height = 22
- Top = 6
+ Top = 32
Width = 511
Anchors = [akTop, akLeft, akRight]
+ BorderSpacing.Top = 10
TabOrder = 0
end
object Button1: TButton
+ AnchorSideTop.Control = chkUseExternal
+ AnchorSideTop.Side = asrBottom
Left = 538
Height = 20
- Top = 6
+ Top = 32
Width = 70
Anchors = [akTop, akRight]
+ AutoSize = True
+ BorderSpacing.Top = 10
Caption = 'Select'
OnClick = Button1Click
TabOrder = 1
end
+ object chkUseExternal: TCheckBox
+ Left = 13
+ Height = 18
+ Top = 4
+ Width = 163
+ Caption = 'Use external converter'
+ TabOrder = 2
+ end
end
end
object OpenDialog1: TOpenDialog
diff --git a/components/chelper/extconvdialog.pas b/components/chelper/extconvdialog.pas
index 2af29fd15..5a8305628 100644
--- a/components/chelper/extconvdialog.pas
+++ b/components/chelper/extconvdialog.pas
@@ -17,6 +17,7 @@ type
btnSelect:TButton;
btnEdit:TButton;
Button2:TButton;
+ chkUseExternal:TCheckBox;
chkRecordsPacked:TCheckBox;
chkFuncAreExt:TCheckBox;
chkEnums:TCheckBox;
@@ -134,6 +135,7 @@ begin
Memo1.Lines.Assign(ConvSettings.CtoPasTypes);
edtDefines.Text:=DefineFile;
edtExtTool.Text:=ExtTool;
+ chkUseExternal.Checked:=UseExtTool;
end;
procedure TCtoPasConfig.UIToSettings;
@@ -145,6 +147,7 @@ begin
ConvSettings.CtoPasTypes.Assign(Memo1.Lines);
DefineFile:=edtDefines.Text;
ExtTool:=edtExtTool.Text;
+ UseExtTool:=chkUseExternal.Checked;
end;
end.
diff --git a/components/chelper/tosourceeditor.pas b/components/chelper/tosourceeditor.pas
index 0b51a21a9..2fbbe77f5 100644
--- a/components/chelper/tosourceeditor.pas
+++ b/components/chelper/tosourceeditor.pas
@@ -25,20 +25,12 @@ interface
uses
Classes, SysUtils, Dialogs, LCLType, LCLIntf, Forms,
Menus, MenuIntf, SrcEditorIntf, process, LazIDEIntf, IDEMsgIntf,
- extconvdialog, converteridesettings, cconvconfig;
+ extconvdialog, converteridesettings, cconvconfig, ctopasconvert;
procedure Register;
implementation
-type
- TErrorInfo = record
- isError : Boolean;
- Error : AnsiString;
- ErrorPos : TPoint;
- end;
-
-
function GetErrorInfo(const errstr: AnsiString; var error: TerrorInfo): Boolean;
var
i : Integer;
@@ -58,7 +50,7 @@ begin
i:=Pos(' ', d);
Val( copy(d, 1, i-1), error.ErrorPos.X, err);
- error.Error:=Copy(d, i+1, length(d));
+ error.ErrorMsg:=Copy(d, i+1, length(d));
end;
function DoExtConvert(const t: AnsiString; ParseAll: Boolean; var EndPos: TPoint; var error: TErrorInfo): AnsiString;
@@ -136,8 +128,10 @@ begin
if st.Count=0 then Exit;
i:=0;
d:=st[0];
- if GetErrorInfo(d, error) then d:=st[1];
-
+ if GetErrorInfo(d, error) then begin
+ st.Delete(0);
+ d:=st[0];
+ end;
if d='' then Exit;
i:=Pos(' ', d);
if i>=1 then begin
@@ -159,6 +153,24 @@ begin
end;
end;
+function StringFromFile(const FileName: AnsiString): AnsiString;
+var
+ fs : TFileStream;
+begin
+ Result:='';
+ if not FileExists(FileName) then Exit;
+ try
+ fs:=TFileStream.Create(FileName, fmOpenRead or fmShareDenyNone);
+ try
+ SetLength(Result, fs.Size);
+ fs.Read(Result[1], fs.Size);
+ finally
+ fs.Free;
+ end;
+ except
+ end;
+end;
+
function DoConvertCode(const t: AnsiString; ParseAll: Boolean; var EndPoint: TPoint; var txt: AnsiString; var error: TErrorInfo): Boolean;
begin
Result:=False;
@@ -174,8 +186,22 @@ begin
if Result then cconvconfig.LoadFromFile(ConvFile, ConvSettings)
else ShowMessage('Error: '+ txt);
- end else
- txt:='';
+ end else begin
+ try
+ if FileExists(DefineFile) then
+ ConvSettings.CustomDefines:=StringFromFile(DefineFile)
+ else
+ ConvSettings.CustomDefines:='';
+ txt:=ConvertCode(t, EndPoint, ParseAll, error, ConvSettings);
+ Result:=true;
+
+ except
+ on E: Exception do begin
+ ShowMessage('Error: '+e.Message);
+ Result:=False;
+ end;
+ end;
+ end;
end;
var
@@ -192,6 +218,7 @@ var
err : TErrorInfo;
line : TIDEMessageLine;
parts : TStringList;
+ lcnt : Integer;
begin
if parsing then Exit;
if not Assigned(SourceEditorManagerIntf) or not Assigned(SourceEditorManagerIntf.ActiveEditor) then Exit;
@@ -216,14 +243,17 @@ begin
if p.Y>0 then begin
inc(p.Y, st.Y-1);
st.X:=1;
+ lcnt:=editor.LineCount;
editor.ReplaceText(st, p, s);
+ lcnt:=editor.LineCount-lcnt;
if Assigned(CtoPasConfig) then
CtoPasConfig.SettingsToUI;
- end;
+ end else
+ lcnt:=0;
if err.isError then begin
- inc(err.ErrorPos.Y, st.Y-1);
+ inc(err.ErrorPos.Y, st.Y-1+lcnt);
if Assigned(IDEMessagesWindow) then begin
- s:=Format('%s(%d,%d) Chelper: %s', [ExtractFileName(editor.FileName), err.ErrorPos.Y,err.ErrorPos.X, err.Error]);
+ with err do s:=Format('%s(%d,%d) Chelper: %s', [ExtractFileName(editor.FileName), ErrorPos.Y,ErrorPos.X, ErrorMsg]);
parts:=TStringList.Create;
try
parts.Values['Type']:='Chelper';