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
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to