954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

dinamic array problem

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.
nuclear
Junior Poster in Training
94 posts since Aug 2011
Reputation Points: 2
Solved Threads: 3
 

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.
pyTony
pyMod
Moderator
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
 

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

nuclear
Junior Poster in Training
94 posts since Aug 2011
Reputation Points: 2
Solved Threads: 3
 

What version of Delphi/Object Pascal are you using and with what compiler flags/directives?

Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You