[fpc-pascal] dynamic array as a part of dynamically allocated records behavior

leledumbo leledumbo_cool at yahoo.co.id
Sat Feb 25 13:23:24 CET 2012


Consider the following program:

{$mode objfpc}
type
  TJam = array of Integer;

  TRuang = record
    nm_ruang: string;
    avl: TJam;
  end;

  PRuang = ^TRuang;

var
  x: array of integer;
  TR: TRuang;
  PR: PRuang;
begin
  try
    WriteLn(Length(x));
    WriteLn(Length(TR.avl));
    PR := GetMem(SizeOf(TRuang));
    WriteLn(Length(PR^.avl));
  finally
    FreeMem(PR);
  end;
end.


The code results in AV in the last WriteLn. Is this correct (i.e. intended
behavior)? If yes, what is the correct way to have the PR^.avl initialized
just like TR.avl and x?

--
View this message in context: http://free-pascal-general.1045716.n5.nabble.com/dynamic-array-as-a-part-of-dynamically-allocated-records-behavior-tp5515029p5515029.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.



More information about the fpc-pascal mailing list