Recent

Author Topic: [SOLVED] Bug? in IfThen  (Read 2405 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: [SOLVED] Bug? in IfThen
« Reply #15 on: July 22, 2019, 10:29:35 am »
Well, you can do the following, adding one extra array element, like:
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}{$R+}
  2. uses sysutils,math;
  3. var
  4.   i:integer = -1;
  5.   a:array of integer = ({index 0 is the default}0,6,7,8,9,10);
  6.   t:Boolean;
  7. begin
  8.   writeln(a[ifthen(inrange(i,0,high(a)),i,0) ]);  
  9.   i:=10;
  10.   writeln(a[ifthen(inrange(i,0,high(a)),i,0) ]);  
  11. end.
and the range error disappears .   

A similar trick can be done with EnsureRange.
« Last Edit: July 22, 2019, 10:39:28 am by Thaddy »
Specialize a type, not a var.

 

TinyPortal © 2005-2018