Lazarus

Free Pascal => General => Topic started by: Hartmut on January 17, 2020, 05:21:23 pm

Title: [SOLVED] Is there a $modeswitch to enable initialized variables in {$mode tp} ?
Post by: Hartmut on January 17, 2020, 05:21:23 pm
I want to use an initialized array variable in {$mode tp} like:
Code: Pascal  [Select][+][-]
  1. {$mode tp}
  2. var a: array of integer = nil;

This is not allowed (FPC 3.2.0). But for the most features of {$mode delphi} or {$mode objfpc} there is a {$modeswitch xyz} directive to enable it. In https://www.freepascal.org/docs-html/prog/progsu105.html I didn't find it. Does it not exist?

Thanks in advance.
Title: Re: Is there a $modeswitch to enable initialized variables in {$mode tp} ?
Post by: Thaddy on January 17, 2020, 05:23:34 pm
mode tp doesn't know about dynamic arrays. Use either mode delphi or mode objfpc (syntax differs)
Title: Re: Is there a $modeswitch to enable initialized variables in {$mode tp} ?
Post by: Hartmut on January 17, 2020, 05:30:41 pm
But this compiles (FPC 3.0.4):
Code: Pascal  [Select][+][-]
  1. {$mode tp}
  2. var a: array of integer;
  3.     i: integer;
  4. begin
  5.   SetLength(a, 10);
  6.   for i:=0 to High(a)-1 do  a[i]:=i;
  7. end.  
Title: Re: Is there a $modeswitch to enable initialized variables in {$mode tp} ?
Post by: Jonas Maebe on January 17, 2020, 05:45:20 pm
No, there is no modeswitch for this functionality.
Title: Re: Is there a $modeswitch to enable initialized variables in {$mode tp} ?
Post by: Hartmut on January 17, 2020, 07:26:03 pm
This is sad news (but that's not your fault ;-). Thanks for your help, Jonas.
TinyPortal © 2005-2018