[fpc-pascal] GetSaveFileNameA limited to 100 characters in default name

Alexander Grotewohl alex at dcclost.com
Fri Jun 18 21:32:48 CEST 2021

The Windows API doesn't understand what an 'AnsiString' is and cannot resize it dynamically like FreePascal would do as it is used.

You need to use something like

buf: array[0..512] of char;

TFileName.nMaxFile := sizeof(buf);

But then you should also handle the possibility that the dir is greater than 512 and allocate a bigger buffer as needed.
So maybe dynamically allocating the space would be better.

Alexander Grotewohl
From: fpc-pascal <fpc-pascal-bounces at lists.freepascal.org> on behalf of James Richters via fpc-pascal <fpc-pascal at lists.freepascal.org>
Sent: Friday, June 18, 2021 1:56 PM
To: 'FPC-Pascal users discussions' <fpc-pascal at lists.freepascal.org>
Cc: James Richters <james.richters at productionautomation.net>
Subject: [fpc-pascal] GetSaveFileNameA limited to 100 characters in default name

I’m using GetSaveFileNameA() in a windows console program to obtain a save-as directory and file name, I am passing  sending it a default file name with:


DefaultFileName is an AnsiString that contains a full path and filename.

This all works fine as long as DefaultFileName is 100 characters or less,  if it’s 101 or more, then GetSaveFileNameA() never opens a dialog box and just returns False;

Does anyone know where the 100 character limit is coming from?

TFileName.lpstrFile is a PChar, and DefaultFileName is an AnsiString, Neither of which have a length limit that I know of…

I am doing a Writeln if Both DefaultFileName and TFileName.lpstrFile and they both match, nothing is being truncated.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20210618/321e5d05/attachment.htm>

More information about the fpc-pascal mailing list