[fpc-pascal] Getting multiple files from GetOpenFileNameA
james at productionautomation.net
Wed May 22 19:18:59 CEST 2019
Thank you for the suggestions. Yes the variables are all global. The TFilename came from some C source that I had as an example. I will take your recommendation and just make it a variable. I guess strpas makes a string of all characters until it reaches a #0 ? I'll give that a try. I'll put together the simplest example that demonstrates the issue.
From: fpc-pascal <fpc-pascal-bounces at lists.freepascal.org> On Behalf Of Santiago A.
Sent: Wednesday, May 22, 2019 12:56 PM
To: 'FPC-Pascal users discussions' <fpc-pascal at lists.freepascal.org>
Subject: Re: [fpc-pascal] Getting multiple files from GetOpenFileNameA
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:
> 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
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.
fpc-pascal maillist - fpc-pascal at lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
More information about the fpc-pascal