i need to write a file with the filename containing the current date.. everything works besides the date, it gives a class exception 'run error(3)'
(the importo.text is the text of a TEdit.. but i guess it's irrelevant)
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
...
var
contributo:real;
f:textfile;
...
datee: string;
...
contributo:= (StrToInt(importo.text)/ 100)*4;
datee:= DateToStr(Date);
assignfile(f,'fattura minimi n.'+n.text+' '+datee+'.txt');
rewrite(f);
writeln(f,'Giovanna Migliore');
...
closefile(f);
DateToStr() will return the date formatted according to regional settings. In your case this is almost certainly returning a folder/path delimiter character (/
or \
) which is causing the problem (path not found).
Even if you change your regional settings to avoid using such characters, the code will still fail on other systems if those regional settings are not "compatible". To avoid this you need to ensure that your encoding of the date in the filename is not sensitive to such potential problems.
You could remove/replace any such characters after forming the filename, or you could explicitly encode the date in a manner that will not introduce such characters to start with, similar to:
var
y, m, d: Word;
..
DecodeDate(Date, y, m, d);
dateStr := Format('%4d-%2d-%2d', [y, m, d]);
// e.g. dateStr value for 31st Dec 2016 would be: '2016-12-31'
You could then incorporate the date component values in your filename either by concatenation as required, or directly in a single format statement:
filename := Format('fattura minimi n.%s %4d-%2d-%2d.txt [n.text, y, m, d]);
assignfile(f, filename);