<div dir="ltr">You can do several thins:<br><br>1. use Else !!<br>2. Surround (I hope that the proper spelling) everything in try finally and then in the finally place the free statement.<br>3. Make a shorter code:<br><br>
Result := (condition1) OR (condition2) OR (condition3)<br>Will be the same as your if statment, but shorter.<br><br>Ido<br><br><div class="gmail_quote">On Sun, Aug 22, 2010 at 10:10, Dave Coventry <span dir="ltr"><<a href="mailto:dgcoventry@gmail.com">dgcoventry@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">I have a function that tests for a series of different conditions<br>
according to a value in a 'case...of' block.<br>
<br>
Result:=false;<br>
mylist:=TStringlist.Create;<br>
case i of<br>
1:<br>
begin<br>
if condition1 then<br>
begin<br>
Result:=true;<br>
break;<br>
end;<br>
if condition2 then<br>
begin<br>
Result:=true;<br>
break;<br>
end;<br>
if condition3 then<br>
begin<br>
Result:=true;<br>
end;<br>
end;<br>
2:....;<br>
3:....;<br>
end;<br>
mylist.free;<br>
<br>
The above does not work as the 'case...of' is not considered to be a loop.<br>
Error: BREAK not allowed.<br>
<br>
I could just exit the function, using 'exit' instead of 'break' but I<br>
think I need to free the mylist TStrings.<br>
<br>
Is there a way of doing this or is my best way just to replace 'break'<br>
with 'mylist.free' and 'exit'?<br>
<font color="#888888"><br>
--<br>
_______________________________________________<br>
Lazarus mailing list<br>
<a href="mailto:Lazarus@lists.lazarus.freepascal.org">Lazarus@lists.lazarus.freepascal.org</a><br>
<a href="http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus" target="_blank">http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus</a><br>
</font></blockquote></div><br></div>