The call to GetFullPathName in FFExpandFileName does not check the return result for errors. This appears to be masking a problem that occurs when an empty filename is given to FFExpandFileName. Sometimes when given an empty filename it seemed to return random data, but this problem changed in unpredictable ways and I just circumvented it rather than found the source of the problem. I have altered my FFExpandFileName to something like this to cure these problems:
function FFExpandFileName(const fn: TffFullFileName): TffFullFileName;
var
FNZ : TffMaxPathZ;
EFNZ : TffMaxPathZ;
FileNamePos : PAnsiChar;
i: integer;
err: integer;
begin
if Length(fn) = 0 then
Result := fn
else begin
i := GetFullPathName(FFStrPCopy(FNZ, fn), sizeof(EFNZ), EFNZ, FileNamePos);
if i = 0 then begin
err := GetLastError;
Exception.raise('FFExpandFileName error. ' + IntToStr(err) + ': ' + SysErrorMessage(err) + ' fn = ' + string(fn));
end;
Result := FFStrPasLimit(EFNZ, pred(sizeof(TffFullFileName)));
end;
end;