[fpc-pascal] Getting multiple files from GetOpenFileNameA

Santiago A. svaa at ciberpiula.net
Wed May 22 18:55:45 CEST 2019


El 21/05/19 a las 23:17, James Richters escribió:
> I have it defined with the program variables:
>
> Here are all my Uses and Vars:
>
> Uses
>    ptcgraph,sysutils,Windows,Commdlg,Classes,CRT;
>
> Var
> TFilename              : TOpenFileNameA;
> ret                    : array[0..100] of char;
> OpenFileResult         : Boolean;
> LoopX,filenum          : Longint;
> filenamestr            : ansistring;
> File_Stringlist        : tstringList;

Are all those variables global unit scope?

Some points about design:
1) I think that file_StringList should be a parameter passed to the 
function GetFilesIntoStringlist and created by the caller.
Procedure GetFilesIntoStringlist(var File_Stringlist:TStrings);

2) "TFilename" is a bad name for a variable. First, it is clashes with a 
system type name. Second, starting it with "T" looks like a type name. 
Rename to CurrentFileName, or OpenFileForWin, or something like that.

Try this way. Instead of adding each char to the string, that means 
reallocating, use the standard function StrPas

           Loopx:=0;
           Repeat
              Filenamestr:=StrPas(@TFileName.lpstrFile[loopX]);
              Writeln(Filenamestr);
              File_Stringlist.add(Filenamestr);
              inc(Loopx,length(Filenamestr)+1);
           Until TFileName.lpstrFile[loopx]=#0;


Write the simplest project with this function that raises the error and 
we can run and reproduce. Nevertheless, if you get random errors it is 
some kind of memory error, probably overwrite in some place. It doesn't 
look the problem is here.

-- 
Saludos

Santiago A.




More information about the fpc-pascal mailing list