Forum > General

Dynamic array of user-defined records.

(1/1)

idealis:
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;
           end;

function ObtenerBancosDBF(var Salida: array of TBanco): Integer;
var
  Limite: Integer;
  DatosOrigen: TDbf;
begin
  Limite := 0;
  // Open DBF
  While not(DatosOrigen.EOF) do begin
    Inc(Limite);
    SetLength(Salida,Limite);
    Salida[Limite-1].Numero := FieldByName('Numero').AsString;
    Salida[Limite-1].Nombre := FieldByName('Nombre').AsString;
    Salida[Limite-1].NombreCorto := FieldByName('Domicilio').AsString;
    DatosOrigen.Next;
  end;
  DatosOrigen.Close;
end;
--- 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

eny:
Try:

--- 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...

Martin_fr:

--- 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" http://www.freepascal.org/docs-html/ref/refsu57.html#x137-14400011.4.5

which differs from a dynamic array  http://www.freepascal.org/docs-html/ref/refsu14.html#x38-440003.3.1

idealis:
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. :)

Cheers!

- idealis

Navigation

[0] Message Index

Go to full version