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

James Richters james.richters at productionautomation.net
Sun Jun 20 02:09:38 CEST 2021


>It's curious, I'm not completely sure we are reasoning about the same
function and record.
It seems I should not be using TFilename as the variable name.
I'm using    a variable called TFileName with GetSaveFileNameA() 
Here is the relevant code.. after I fixed it to use Max_Path
 
Uses CRT,CRT.Helper,Classes,Sysutils,windows,commdlg,Math,Process;
 
Var
   TFilename           : TOpenFileNameA;
   DefaultFileName   : AnsiString = '' ;
   OutputFileName   : AnsiString = '' ;
 
fillchar(TFileName, sizeof(TFileName), 0);
TFileName.lStructSize:=sizeof(TFileName);
TFileName.hwndOwner:=0;
TFileName.nMaxFile:=Max_Path+1;
TFileName.lpstrFile:=Pchar('');
TFileName.Flags := OFN_EXPLORER or OFN_FILEMUSTEXIST or OFN_HIDEREADONLY;
TFileName.lpstrDefExt:='';
TFileName.lpstrTitle:='Save File As:';
TFileName.lpstrFilter:='TAP Files (*.Tap)'+#0+'*.Tap'+#0+'All Files
(*.*)'+#0+'*.*'+#0;
TFileName.lpstrFile:=Pchar(DefaultFileName);
SaveAsResult:=GetSaveFileNameA(@TFilename);
.
.
OutputFileName:= strpas(TFileName.lpstrFile);
.
. 
Assign(TapFile,OutputFileName);
ReWrite(TapFile);
.
.
 
It seems TFileName is already defined and I am re-defining it.  TFileName
was not my idea.. that is not how I name my variables. It's something I got
from an example on how to use GetSaveFileNameA() that I copied and pasted
and then adjusted. that is also where TFileName.nMaxFile:=100; came from
that caused my original problem.
 
I don't have a really good understanding of the conventions of putting
various letters in front of Variables, like the T.. but I would never put
the T there myself.. variables I define never have the T.. so if I wasn't
copying an example, I would have done something like:
 
SaveAsFile : TOpenFileNameA;
 
James
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20210619/3679affd/attachment-0001.htm>


More information about the fpc-pascal mailing list