I think you should have a look at this documentation on strings, particularly for PChar :
https://www.freepascal.org/docs-html/ref/refsu9.html

Le 20/06/2021 à 02:09, James Richters a écrit :
DefaultFileName: AnsiString = '' ;
So Length(DefaultFileName) = 0
TFileName.nMaxFile:=Max_Path+1;
This says that lpstrFile points to a buffer of size Max_Path+1.

TFileName.lpstrFile:=Pchar('');

But here you make it point to a buffer of size 1 (a constant with just a null char)

TFileName.Flags:= OFN_EXPLORER or OFN_FILEMUSTEXIST or OFN_HIDEREADONLY;

I think OFN_FILEMUSTEXIST forbid to create new file.

TFileName.lpstrFile:=Pchar(DefaultFileName);

New assignment of lpstrFile, make it point to DefaultFileName, which seems to be of length 0, so a buffer of size 1 (a constant with just a null char at the end).

I think you should at least add the begining of your code : SetLength( DefaultFileName, Max_Path);

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…

The name is a bit misleading, but as soon as it's a variable of type TOpenFileNameA, it's fine.


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

Reply via email to