Recent

Author Topic: [SOLVED] Is there a $modeswitch to enable initialized variables in {$mode tp} ?  (Read 1030 times)

Hartmut

  • Hero Member
  • *****
  • Posts: 749
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.
« Last Edit: January 17, 2020, 07:26:37 pm by Hartmut »

Thaddy

  • Hero Member
  • *****
  • Posts: 14364
  • Sensorship about opinions does not belong here.
Re: Is there a $modeswitch to enable initialized variables in {$mode tp} ?
« Reply #1 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)
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Hartmut

  • Hero Member
  • *****
  • Posts: 749
Re: Is there a $modeswitch to enable initialized variables in {$mode tp} ?
« Reply #2 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.  

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1059
Re: Is there a $modeswitch to enable initialized variables in {$mode tp} ?
« Reply #3 on: January 17, 2020, 05:45:20 pm »
No, there is no modeswitch for this functionality.

Hartmut

  • Hero Member
  • *****
  • Posts: 749
Re: Is there a $modeswitch to enable initialized variables in {$mode tp} ?
« Reply #4 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