Forum > General

Dynamic array of user-defined records.


Hi again! As you probably noticed I'm opening several topics and they are about rather basic questions, hey, I'm new to Delphi and Lazarus so please bear with me. :D

This time I want to know this: Is it possible to have dynamic arrays of user-defined records? I wrote this code to see if I could get the answer, but the compiler fails.

--- Code: ---type
  TBanco = Record
             Numero    : Integer;
             Nombre    : String;
             Domicilio : String;

function ObtenerBancosDBF(var Salida: array of TBanco): Integer;
  Limite: Integer;
  DatosOrigen: TDbf;
  Limite := 0;
  // Open DBF
  While not(DatosOrigen.EOF) do begin
    Salida[Limite-1].Numero := FieldByName('Numero').AsString;
    Salida[Limite-1].Nombre := FieldByName('Nombre').AsString;
    Salida[Limite-1].NombreCorto := FieldByName('Domicilio').AsString;
--- End code ---

This specific line gives me a "type mismatch" error.

--- Code: ---SetLength(Salida,Limite);
--- End code ---

But this is supposed to work, according to some stuff that I read on the Internet. What is wrong here?

Thanks :)

- idealis


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type  TBanco = Record             Numero    : Integer;             Nombre    : String;             Domicilio : String;           end;  TBancoArray = array of TBanco; function ObtenerBancosDBF(var Salida: TBancoArray): Integer;//etc...


--- Quote from: idealis on October 29, 2010, 12:38:06 pm ---
--- Code: ---function ObtenerBancosDBF(var Salida: array of TBanco): Integer;

--- End code ---

--- End quote ---

What you have there is an "open array"

which differs from a dynamic array

Thank you so much for the replies, friends.
Also, Martin_fr, those links were very useful, I will read more about it when I have some time. :)


- idealis


[0] Message Index

Go to full version