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
https://dcclost.com
________________________________
From: fpc-pascal <fpc-pascal-boun...@lists.freepascal.org> on behalf of James 
Richters via fpc-pascal <fpc-pascal@lists.freepascal.org>
Sent: Friday, June 18, 2021 1:56 PM
To: 'FPC-Pascal users discussions' <fpc-pascal@lists.freepascal.org>
Cc: James Richters <james.richt...@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:



TFileName.lpstrFile:=Pchar(DefaultFileName);



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.



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

Reply via email to