<HTML>
<style> BODY { font-family:Arial, Helvetica, sans-serif;font-size:12px; }</style>Ah, okay. In my case, it doesn't work if the set you specify is a constant or variable defined elsewhere.<br>
<div><br>
</div><div>e.g.<br>
<br>
const Delimiters: array[0..5] of Char = [#9, #10, #12, #13, #26, #32];<br>
<br>
if C in Delimiters then...</div><div><br>
</div><div>If you do that, you get a compiler error about 'in' not being overloaded or some such.<br>
</div><div><br>
</div><div>Gareth aka. Kit<br>
</div> <br>
<br>
<span style="font-weight: bold;">On Tue 05/03/19 06:36 , Michael Van Canneyt michael@freepascal.org sent:<br>
</span><blockquote style="BORDER-LEFT: #F5F5F5 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT:0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
<br>
<br>
On Tue, 5 Mar 2019, J. Gareth Moreton wrote:
<br>
<br>
<span style="color: rgb(102, 102, 102);">> Hi everyone,
</span><br>
<span style="color: rgb(102, 102, 102);">>
</span><br>
<span style="color: rgb(102, 102, 102);">> I've developed a couple of "in" operator overrides so you can use " in "
</span><br>
<span style="color: rgb(102, 102, 102);">> (useful in parsing tools, say, to see if a character belongs to a set of
</span><br>
<span style="color: rgb(102, 102, 102);">> delimiters) and " in ". e.g.
</span><br>
<span style="color: rgb(102, 102, 102);">>
</span><br>
<span style="color: rgb(102, 102, 102);">> operator in(_Char: Char; _Set: array of Char): Boolean;
</span><br>
<span style="color: rgb(102, 102, 102);">> var
</span><br>
<span style="color: rgb(102, 102, 102);">> C: Char;
</span><br>
<span style="color: rgb(102, 102, 102);">> begin
</span><br>
<span style="color: rgb(102, 102, 102);">> Result := False;
</span><br>
<span style="color: rgb(102, 102, 102);">> for C in _Set do
</span><br>
<span style="color: rgb(102, 102, 102);">> if C = _Char then
</span><br>
<span style="color: rgb(102, 102, 102);">> begin
</span><br>
<span style="color: rgb(102, 102, 102);">> Result := True;
</span><br>
<span style="color: rgb(102, 102, 102);">> Exit;
</span><br>
<span style="color: rgb(102, 102, 102);">> end;
</span><br>
<span style="color: rgb(102, 102, 102);">> end;
</span><br>
<span style="color: rgb(102, 102, 102);">>
</span><br>
<span style="color: rgb(102, 102, 102);">> Would these be welcome in one of the core units? And if so, which unit
</span><br>
<span style="color: rgb(102, 102, 102);">> would you recommend?
</span><br>
<br>
At the risk of sounding stupid, but why would you want to add this if the
<br>
compiler supports this out of the box ?
<br>
<br>
var
<br>
C : char;
<br>
<br>
begin
<br>
if ParamCount>0 then
<br>
c:=paramstr(1)[1]
<br>
else
<br>
c:=#0;
<br>
if c in ['a','b','c'] then
<br>
writeln('ok')
<br>
else
<br>
writeln('not ok')
<br>
end.
<br>
<br>
Michael.
<br>
<br>
_______________________________________________<br>
fpc-devel maillist - <a href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a><br>
<a target="_blank" href="<a href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>"><span style="color: red;">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</span></a><br>
<br>
</blockquote></HTML>