Its something really basic, but for some reason i cant get my dinamic array to work. Keep getting a message that i need to add the "[]", but then i would create a static array, not a dinamic one. The code:

program Noname0;
var arr : array of integer;
begin
  WriteLn('Hi!');
  Readln;
end.

I copy pasted your code in empty project in Lazarus and it run without error:

program Project1;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes
  { you can add units after this };

{$R *.res}
var arr : array of integer;
begin
  WriteLn('Hi!');
  Readln;
end.

Also I run as more advanced code some code from: http://delphi.about.com/od/beginners/a/arrays.htm .

program dynamic;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes
  { you can add units after this };

{$R *.res}
var
 Vector: array of Integer;
 k : integer;
begin
     SetLength(Vector, 10) ;
     for k := Low(Vector) to High(Vector) do
         Vector[k] := k*10;
     //...
     //now we need more space
     SetLength(Vector, 20) ;
     Vector[11] := 10;
     for k := Low(Vector) to High(Vector) do writeln(k, ', ', Vector[k]);
     //here, Vector array can hold up to 20 elements
     //(it already has 10 of them)
     readln;
end.

Edited 5 Years Ago by pyTony: n/a

I know it should work with no errors, dont know where the problem is.

This question has already been answered. Start a new discussion instead.