[fpc-pascal] Getting multiple files from GetOpenFileNameA
james at productionautomation.net
Tue May 21 21:12:41 CEST 2019
This is the function I came up with to use GetOpenFileNameA() to get multiple files, and put the file names all into a StringList.
I think I am doing something fundamentally wrong here because I can run this in a loop sometimes 2 or 4 times, or sometimes 30 times, and it seems to work but eventually my program crashes with an access violation at various different points.. it's not always the same point in the program that crashes, but if I rig this to only build the stringlist once, I can run the rest of the process over and over including the GetOpenFileNameA() without issues. I wonder if my method of putting the files names into the stringlist is flawed, I made it up myself based on what I could gather from the documentation of GetOpenFileNameA(), maybe I am missing something.. or maybe the way I'm setting the string list to nil and then re-creating it is causing an issue? The Writeln's I put in seem to be what I expect, but still it crashes at some point when I run this in a loop. Below is my procedure, can anyone see anything I am doing in a bad way that would cause the instability I am experiencing?
I am freeing the stringlist first thing, and I only create a new one if GetOpenFileNameA()is successful. Then later on I check for the existence of the stringlist and if it's there, I process my files, the loop back and run this again, if not, I just exit, because if the string list does not exist then GetOpenFileNameA() was closed without selecting any files, so the process is complete.
Another issue with this.... I am only able to select 6 or 7 files with this and then GetOpenFileNameA() returns with False... I suspect I need to make a memory buffer for more files but don't know how to do that, anyone have any advice on how to fix that?
IF (File_Stringlist<>Nil) Then
fillchar(TFileName, sizeof(TFileName), 0);
TFileName.Flags := OFN_EXPLORER or OFN_FILEMUSTEXIST or OFN_ALLOWMULTISELECT;
TFileName.lpstrTitle:='Production Automation Open Dpax File:';
TFileName.lpstrFilter:='Draw.Pax Files (*.DPax)'+#0+'*.DPax'+#0;
If Drawpaxfilename<>'' then
If OpenFileResult then
IF File_Stringlist=Nil Then
if TFileName.lpstrFile[loopx]<>#0 Then
If File_Stringlist.Count=1 then
Writeln(File_Stringlist.Count,' File Selected')
Writeln(File_Stringlist.Count-1,' Files Selected');
More information about the fpc-pascal