View Issue Details

IDProjectCategoryView StatusLast Update
0036082LazarusIDEpublic2019-09-30 08:31
ReporterserbodAssigned ToMartin Friebe 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product VersionProduct Build61897 
Target VersionFixed in Version2.0.6 
Summary0036082: Import Editor Macros - Index out of range (-1)
DescriptionWhen importing editor macros from XML file, "Index out of range (-1)" error occured
Additional Information==== Faulty code:
function TIdeMacroEventReader.PosToXY: TPoint;
var
  f: TStringList;
begin
  f := TStringList.Create;
  f.Text := copy(FOrigText,1 ,FPos);
  Result.y := f.Count;
  Result.x := length(f[f.Count-1])+1; // <<< when f.Count = 0
  f.Free;
end;

==== Call stack:
#0 fpc_raiseexception at :0
0000001 CLASSES$_$TSTRINGS_$__$$_ERROR$ANSISTRING$LONGINT at :0
0000002 CLASSES$_$TSTRINGLIST_$__$$_CHECKINDEX$LONGINT at :0
0000003 CLASSES$_$TSTRINGLIST_$__$$_GET$LONGINT$$ANSISTRING at :0
0000004 POSTOXY(0x733fb40) at editormacrolistviewer.pas:796
0000005 ADDERROR(0x733fb40, 0x8a38598 'Unknown Command "procedur'...) at editormacrolistviewer.pas:804
0000006 PARSENEXTEVENT(0x733fb40) at editormacrolistviewer.pas:877
0000007 SETFROMSOURCE(0x733f780, 0x6d33d78 'procedure FindNextSelecte'...) at editormacrolistviewer.pas:692
0000008 READFROMXMLCONF(0x733f780, 0x12e35f0, 0x1013e0960 'EditorMacros/Macro1/') at editormacrolistviewer.pas:723
0000009 MNIMPORTCLICK(0x79cd990, 0x6f97c10) at editormacrolistviewer.pas:1243

==== Suggested fix:
function TIdeMacroEventReader.PosToXY: TPoint;
var
  f: TStringList;
begin
  f := TStringList.Create;
  try
    f.Text := Copy(FOrigText, 1, FPos);
    Result.y := f.Count;
    if f.Count > 0 then
      Result.x := Length(f[f.Count-1]) + 1
    else
      Result.x := 0;
  finally
    f.Free;
  end;
end;


==== Also faulty function:

function TIdeMacroEventReader.ParseNextEvent: Boolean;
  procedure SkipNum(var i: integer);
  begin
    while (i <= Length(FText)) and (FText[i] in ['0'..'9']) do inc (i);
  end;
  procedure SkipSpace(var i: integer);
  begin
    while (i <= Length(FText)) and (FText[i] in [' '..0000009, 0000013, 0000010]) do inc (i); // <<< ' '..0000009 range treated as empty range with warning!
  end;
TagsNo tags attached.
Fixed in Revision61898
LazTarget2.0.6
Widgetset
Attached Files

Activities

Martin Friebe

2019-09-18 17:52

manager   ~0118105

Fixed.
Error at start should be (1,1). So slightly amended your proposed fix.

Issue History

Date Modified Username Field Change
2019-09-18 14:46 serbod New Issue
2019-09-18 16:52 Martin Friebe Assigned To => Martin Friebe
2019-09-18 16:52 Martin Friebe Status new => assigned
2019-09-18 17:52 Martin Friebe Status assigned => resolved
2019-09-18 17:52 Martin Friebe Resolution open => fixed
2019-09-18 17:52 Martin Friebe Fixed in Version => 2.0.6
2019-09-18 17:52 Martin Friebe Fixed in Revision => 61898
2019-09-18 17:52 Martin Friebe LazTarget => 2.0.6
2019-09-18 17:52 Martin Friebe Note Added: 0118105
2019-09-30 08:31 serbod Status resolved => closed