This is my function that seems to cause this more than anything else… it’s ridiculously simple…
Function ExtractFilePathAndNameWithoutExt(Filenametouse:String):String;
Begin
ExtractFilePathAndNameWithoutExt := copy(Filenametouse,1,rpos(ExtractFileExt(Filenametouse),Filenametouse)-1);
End;I stuck a bunch of Writeln’s in it to try to figure out what the heck is happening… my normal response when I need to track something down and the debug information is not clear.
Function ExtractFilePathAndNameWithoutExt(Filenametouse:String):String;
Begin
Writeln('Filenametouse: ',Filenametouse);
Writeln('ExtractFileExt(Filenametouse): ',ExtractFileExt(Filenametouse));
Writeln('rpos(ExtractFileExt(Filenametouse),Filenametouse): ',rpos(ExtractFileExt(Filenametouse),Filenametouse));
Writeln('Length(Filenametouse): ',Length(Filenametouse));
Writeln('copy(Filenametouse,1,rpos(ExtractFileExt(Filenametouse),Filenametouse)-1): ',copy(Filenametouse,1,rpos(ExtractFileExt(Filenametouse),Filenametouse)-1));
ExtractFilePathAndNameWithoutExt := copy(Filenametouse,1,rpos(ExtractFileExt(Filenametouse),Filenametouse)-1);
End;The results I get when it fails are :
Writeln('Filenametouse: ',Filenametouse); This gives me what I expect: a valid filename with full path
Writeln('ExtractFileExt(Filenametouse): ',ExtractFileExt(Filenametouse)); This gives me what I expect: the extension only from the above file name
Writeln('rpos(ExtractFileExt(Filenametouse),Filenametouse): ',rpos(ExtractFileExt(Filenametouse),Filenametouse)); This is what’s causing the error… strangely it does the Writeln AFTER the error.. I don’t understand how that can even happen.
I tested this selecting the same 3 files over and over until it failed. Here is the Console output showing the last good set and the failre:
-------------------------------------- Console Output-----------------------------
M:\
elipse_1.dpax
elipse_2.dpax
elipse_3.dpax
4 Files Selected
Filenametouse: M:\elipse_1.dpax
ExtractFileExt(Filenametouse): .dpax
rpos(ExtractFileExt(Filenametouse),Filenametouse): 12
Length(Filenametouse): 16
copy(Filenametouse,1,rpos(ExtractFileExt(Filenametouse),Filenametouse)-1): M:\elipse_1
Drawing: M:\elipse_1
Filenametouse: M:\elipse_2.dpax
ExtractFileExt(Filenametouse): .dpax
rpos(ExtractFileExt(Filenametouse),Filenametouse): 12
Length(Filenametouse): 16
copy(Filenametouse,1,rpos(ExtractFileExt(Filenametouse),Filenametouse)-1): M:\elipse_2
Drawing: M:\elipse_2
Filenametouse: M:\elipse_3.dpax
ExtractFileExt(Filenametouse): .dpax
rpos(ExtractFileExt(Filenametouse),Filenametouse): 12
Length(Filenametouse): 16
copy(Filenametouse,1,rpos(ExtractFileExt(Filenametouse),Filenametouse)-1): M:\elipse_3
Drawing: M:\elipse_3
M:\
elipse_1.dpax
elipse_2.dpax
elipse_3
4 Files Selected
Filenametouse: M:\elipse_1.dpax
ExtractFileExt(Filenametouse): .dpax
An unhandled exception occurred at $0040ED1A:
EAccessViolation: Access violation
$0040ED1A
$004026DB main, line 119 of i:/programming/gcode/mill/plotdraw.pax.pas
rpos(ExtractFileExt(Filenametouse),Filenametouse):
--------------------------------------End Console Output-----------------------------
Does anyone have any idea at all why RPOS could not determine that the position of .dpax in M:\elipse_1.dpax was 12 like every other time I ran this????????????
I ran this while looking at task manager and it starts up with 9.2MB of memory and that stays consistent, so I don’t think I have a memory leak anywhere. Any ideas?? I’m running on Windows 10, compiling with FPC 3.0.4RC1 with the FPC text IDE.
James
