[fpc-pascal] Overloading IN operator

Fabio Luis Girardi fluisgirardi at gmail.com
Wed Dec 13 02:37:32 CET 2017


Hi all!

I want to extend some operators in Freepascal. I want to achieve something
like this:

if aStr in ['string item 1', 'string item 2', 'string item 3'] then
  ...
else
  ...;

Following the examples to overload operators, I wrote:

operator in (a:String; b:array of string):Boolean;
var
  c: Integer;
begin
  Result:=false;
  for c:=0 to High(b) do
    if b[c]=a then begin
      result:=true;
      exit;
    end;
end;

But when I try compile this piece of code:

if aStr in ['string item 1', 'string item 2', 'string item 3'] then
  ...
else
  ...;

I got:

Error: Ordinal expression expected

Looking to Freepascal documentation, IN operator overloading is possible:

https://www.freepascal.org/docs-html/ref/refse104.html

So if the overloading is possible, Is possible to get this example working?

-- 
The best regards,

Fabio Luis Girardi
PascalSCADA Project
http://sourceforge.net/projects/pascalscada
http://www.pascalscada.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20171212/e160e544/attachment.html>


More information about the fpc-pascal mailing list