<p style="padding:0 0 0 0; margin:0 0 0 0;">Hi, if you mean this:</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">function CategoryIndexOf(Name: String): Integer;</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> var</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> i: Integer;</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> begin</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> for i:= lstCategory.Items.Count-1 downto 0 do begin</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> if lstCategory.Items[i] = Name</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> then Break;</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> end;</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> Result := i;</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> if (i = lstCategory.Items.IndexOf(cActionListEditorUnknownCategory))</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> and (i = lstCategory.Items.IndexOf(cActionListEditorAllCategory))</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> then Result := 0;</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> end;</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">It can IMO cause random and hardly reproducible bugs.</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">V.</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">______________________________________________________________<br />
> Od: Juha Manninen <juha.manninen62@gmail.com><br />
> Komu: FPC-Pascal users discussions <fpc-pascal@lists.freepascal.org><br />
> Datum: 10.10.2016 12:16<br />
> Předmět: [fpc-pascal] Using for-loop index variable after loop<br />
></p>
I have always avoided using a for-loop index variable after the loop.<br />
I thought its value can be unpredictable in some situations when the<br />
compiler reuses its register or memory etc.<br />
<br />
I noticed the ActionListEditor in Lazarus sources has code that uses it after the loop.<br />
<br />
Juha<br />
_______________________________________________<br />
fpc-pascal maillist - fpc-pascal@lists.freepascal.org<br />
<a href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a><br />