Recent

Author Topic: [Solved] Using "in" for array of string  (Read 3351 times)

AlexTP

  • Hero Member
  • *****
  • Posts: 2386
    • UVviewsoft
[Solved] Using "in" for array of string
« on: August 14, 2021, 09:24:25 pm »
Code
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}{$H+}
  2.                        
  3. ...
  4. const
  5.   ar: array of string = ('a','b');
  6.  
  7. procedure TForm1.FormCreate(Sender: TObject);
  8. var
  9.   s: string;
  10. begin
  11.   s:= 'a';
  12.   if s in ar then ;
  13.  
  14. end;
  15.  

FPC error: "Operator is not overloaded".
Lazarus 2.3.0 r65368M FPC 3.2.1 x86_64-linux-gtk2
When this "in" must work?
« Last Edit: August 14, 2021, 11:52:33 pm by Alextp »

AlexTP

  • Hero Member
  • *****
  • Posts: 2386
    • UVviewsoft
Re: Using "in" for array of string
« Reply #1 on: August 14, 2021, 09:50:03 pm »
Free Pascal Compiler version 3.2.1-r48494 [2021/02/02] for x86_64

Kays

  • Hero Member
  • *****
  • Posts: 569
  • Whasup!?
    • KaiBurghardt.de
Re: Using "in" for array of string
« Reply #2 on: August 14, 2021, 10:01:05 pm »
[…] When this "in" must work?
Did you mean the following?
Code: Pascal  [Select][+][-]
  1. for s in ar do
The in operator as a Boolean test was never defined/overloaded for any array. Only for set data types you can check membership with in.
Yours Sincerely
Kai Burghardt

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: Using "in" for array of string
« Reply #3 on: August 14, 2021, 10:03:24 pm »
When this "in" must work?

When the second operand is a set.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories



simone

  • Hero Member
  • *****
  • Posts: 573
Re: Using "in" for array of string
« Reply #6 on: August 14, 2021, 11:38:18 pm »
Microsoft Windows 10 64 bit - Lazarus 3.0 FPC 3.2.2 x86_64-win64-win32/win64

 

TinyPortal © 2005-2018