[fpc-pascal] GetSaveFileNameA limited to 100 characters in default name
jean.suzineau at wanadoo.fr
Sat Jun 19 15:54:49 CEST 2021
It's curious, I'm not completely sure we are reasoning about the same
function and record.
You mention TFileName but for me in FPC 3.2.0:
- TFileName is declared as "TFileName= type string;" in sysutilh.inc.
- OPENFILENAMEA is declared as record in CommDlg.pp line 94
-function GetSaveFileNameA is imported from Comdlg32.dll in CommDlg.pp
function GetSaveFileNameA(_para1:LPOPENFILENAME):WINBOOL; stdcall;
external 'comdlg32' name 'GetSaveFileNameA';
Le 19/06/2021 à 02:51, James Richters via fpc-pascal a écrit :
> This got me thinking… my default filename is just a recommended
> default… but TFileName.lpstrFileis also what returns the filename to
> use, and the user could use the save-as dialog to add a directory, and
> change the name of the file to something else..etc… so the file name
> could be significantly larger than the default…
> So I think I’m best off setting TFileName.nMaxFile:= Max_Path;then
> TFileName.lpstrFile will always be able to hold anything the operating
> system can support.
The nMaxFile value include the terminal null character, so it should be
Max_Path+1, and it must be the size of the buffer lpstrFile is pointing to.
You shouldn't use "TFileName.lpstrFile:=Pchar(DefaultFileName);" because
in this case lpstrFile will point to a buffer of size
And to get the value back from the function, given a variable s: string,
you should do something like s:= StrPas( TFileName.lpstrFile);
From Microsoft documentation:
The size, in characters, of the buffer pointed to by lpstrFile. The
buffer must be large enough to store the path and file name string or
strings, including the terminating NULL character. The GetOpenFileName
functions return FALSE if the buffer is too small to contain the file
information. The buffer should be at least 256 characters long.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-pascal