<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">El 23/05/19 a las 13:52, James Richters
escribió:<br>
</div>
<blockquote type="cite"
cite="mid:c93f01d5115e$0121fba0$0365f2e0$@productionautomation.net">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
{mso-style-priority:99;
mso-style-link:"Plain Text Char";
margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
span.PlainTextChar
{mso-style-name:"Plain Text Char";
mso-style-priority:99;
mso-style-link:"Plain Text";
font-family:"Calibri",sans-serif;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoPlainText"><span style="font-size:14.0pt">I have
put together a program that demonstrates the issue I am
having. I have re-structured it a bit to try to make it
more clear where the problem is.<o:p></o:p></span></p>
<p class="MsoPlainText"><span style="font-size:14.0pt">While
putting this together, I was able to get it to run fine with
no problems if I did not try to put GetOpenFileNameA back to
the directory of the last file I processed. Including a file
sent in as a parameter. If I set
Open_File.lpstrFile:=Pchar(Target_File+#0+#0); where
Target_File is the complete path and file name of the last
file I processed, If I select only one file, then the next
time around it DOES work.. and will put me in the directory
of Target_File and will show the filename of Target_File as
a default, but if I select more than one file, the next time
around, it crashes.. I have detailed the crash information
in the sameple program comments.<o:p></o:p></span></p>
<p class="MsoPlainText"><span style="font-size:14.0pt">Another
way I wish to run this is to leave Open_File.lpstrFile alone
and use Open_File.lpstrInitialDir to put me in the directory
of the last processed file, but not specify a default
filename. I can’t get this to work correctly at all, but if
I use Open_File.lpstrInitialDir without Open_File.lpstrFile
then it does not crash, I am just not put in the directory
I expect to be in. <o:p></o:p></span></p>
<p class="MsoPlainText"><span style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span style="font-size:14.0pt">Any
Advice or suggestions on any of this, or on how I could
improve the structure or methods of this program are greatly
appreciated.</span></p>
</div>
</blockquote>
<br>
At the beginning you set <br>
Open_File.lpstrFile:=ret;<br>
<br>
That is right Open_File.lpstrFile points to "ret", and "ret" is an
array of 100000, a good buffer. <br>
<br>
<br>
The problem is here:<br>
<pre><tt>Open_File.lpstrFile:=Pchar(Target_File+#0+#0);</tt></pre>
That is wrong. Now <tt>Open_File.lpstrFile</tt> doesn't point to
"ret" anymore, now it points to a string with <tt>length(Target_File)+2</tt>.
But <tt>Open_File.nMaxFile:=100000</tt>, so the GetOpenFileNameA
thinks there is plenty of room, so rises no error and overwrites
whatever is after Target_File+#0+#0.<br>
<br>
instead of<br>
<pre><tt>Open_File.lpstrFile:=Pchar(Target_File+#0+#0);</tt></pre>
write<br>
<pre><tt>ret:=Pchar(Target_File+#0)</tt></pre>
You should initialize to "ret" in each loop, in fact, it should be
initialized inside the procedure. and <tt>Open_File.lpstrFilter:='All
Files (*.*)'+#0+'*.*'+#0</tt>; needs an extra #0;<tt><br>
<br>
<br>
</tt>In addition, just for style, instead of<tt><br>
<br>
</tt><tt><tt>Open_File.nMaxFile:=100000<br>
</tt></tt>write<tt><tt><br>
</tt></tt><tt><tt><tt>Open_File.nMaxFile:=sizeOf(ret);<br>
<br>
</tt></tt></tt>And why are all those variables global if they
are only used inside the procedure?<tt><tt><tt><br>
<br>
</tt></tt></tt>And instead of this<tt><tt><tt><br>
</tt></tt></tt><br>
<p class="MsoPlainText"><span
style="font-size:14.0pt;font-family:Consolas">
Filenum:=0;</span></p>
<p class="MsoPlainText"><span
style="font-size:14.0pt;font-family:Consolas"> Repeat</span></p>
<p class="MsoPlainText"><span
style="font-size:14.0pt;font-family:Consolas">
Inc(Filenum);</span></p>
<p class="MsoPlainText"><span
style="font-size:14.0pt;font-family:Consolas"> If
(Filenum<File_Stringlist.Count) Then</span></p>
<p class="MsoPlainText"><span
style="font-size:14.0pt;font-family:Consolas">
Begin</span></p>
<p class="MsoPlainText"><span
style="font-size:14.0pt;font-family:Consolas">
Target_<a class="moz-txt-link-freetext" href="File:=File_Stringlist">File:=File_Stringlist</a>[0];</span></p>
<p class="MsoPlainText"><span
style="font-size:14.0pt;font-family:Consolas">
If Target_File[Length(Target_File)]<>'\' Then</span></p>
<p class="MsoPlainText"><span
style="font-size:14.0pt;font-family:Consolas">
Target_<a class="moz-txt-link-freetext" href="File:=Target_File+'\">File:=Target_File+'\</a>';</span></p>
<p class="MsoPlainText"><span
style="font-size:14.0pt;font-family:Consolas">
Target_<a class="moz-txt-link-freetext" href="File:=Target_File+File_Stringlist">File:=Target_File+File_Stringlist</a>[Filenum];</span></p>
<p class="MsoPlainText"><span
style="font-size:14.0pt;font-family:Consolas">
Process_File(Target_File);</span></p>
<p class="MsoPlainText"><span
style="font-size:14.0pt;font-family:Consolas">
End;</span></p>
<p class="MsoPlainText"><span
style="font-size:14.0pt;font-family:Consolas"> Until
Filenum>=File_Stringlist.Count;</span></p>
<span style="font-size:14.0pt;font-family:Consolas"><br>
Replace with<br>
<br>
</span> <span
style="font-size:14.0pt;font-family:Consolas"><span
style="font-size:14.0pt;font-family:Consolas">Target_<a class="moz-txt-link-freetext" href="File:=IncludeTrailingPathDelimiter(">File:=IncludeTrailingPathDelimiter(</a></span></span><span
style="font-size:14.0pt;font-family:Consolas">File_Stringlist[0]);</span>
<p class="MsoPlainText"><span
style="font-size:14.0pt;font-family:Consolas"> for
file_num:=1 to File_Stringlist.count-1 do</span></p>
<p class="MsoPlainText"><span
style="font-size:14.0pt;font-family:Consolas"> </span><span
style="font-size:14.0pt;font-family:Consolas"><span
style="font-size:14.0pt;font-family:Consolas">Process_File(Target_File+</span></span><span
style="font-size:14.0pt;font-family:Consolas"><span
style="font-size:14.0pt;font-family:Consolas"><span
style="font-size:14.0pt;font-family:Consolas">File_Stringlist[Filenum]</span>);</span></span></p>
<br>
FOR is you friend<br>
<br>
<br>
<pre class="moz-signature" cols="72">--
Saludos
Santiago A.
</pre>
</body>
</html>