Thanks for the function.   I don't think that my function is the problem at 
all.. I've just completed a test where I bypassed my file list and ran it 
several hundred times and my function never caused any problems.... I think I 
have a fundamental problem with the function I disabled to get it to work... 
maybe I am not cleaning up or resetting the way I should be.      I'm going to 
post that function with a separate title to make it clear it's a new topic

James

-----Original Message-----
From: fpc-pascal <fpc-pascal-boun...@lists.freepascal.org> On Behalf Of Bart
Sent: Tuesday, May 21, 2019 12:50 PM
To: FPC-Pascal users discussions <fpc-pascal@lists.freepascal.org>
Subject: Re: [fpc-pascal] RPos Causing Access violation

On Tue, May 21, 2019 at 2:18 PM James Richters <ja...@productionautomation.net> 
wrote:

> Function 
> ExtractFilePathAndNameWithoutExt(Filenametouse:String):String;
>
> Begin
>
>    ExtractFilePathAndNameWithoutExt := 
> copy(Filenametouse,1,rpos(ExtractFileExt(Filenametouse),Filenametouse)
> -1);
>
> End;


From LazFileUtils unit:

function ExtractFileNameWithoutExt(const AFilename: string): string; var
  p: Integer;
begin
  Result:=AFilename;
  p:=length(Result);
  while (p>0) do begin
    case Result[p] of
      PathDelim: exit;
      {$ifdef windows}
      '/': if ('/' in AllowDirectorySeparators) then exit;
      {$endif}
      '.': exit(copy(Result,1, p-1));
    end;
    dec(p);
  end;
end;

writeln(ExtractFileNameWithoutExt('c:\foo\bar\foobar.ext'));
gives:
c:\foo\bar\foobar

--
Bart
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org 
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to