Recent

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

Alextp

  • Hero Member
  • *****
  • Posts: 1408
    • 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: 1408
    • 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

  • Sr. Member
  • ****
  • Posts: 367
  • 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: 3257
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
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and 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

  • Sr. Member
  • ****
  • Posts: 408
Re: Using "in" for array of string
« Reply #6 on: August 14, 2021, 11:38:18 pm »
Microsoft Windows 10 64 bit - Lazarus 2.0.12

 

TinyPortal © 2005-2018