Mega Code Archive

 
Categories / Delphi / Algorithm Math
 

How to use open arrays

Title: How to use open arrays Question: In many procedures it would make sence to have a flexible amount of parameters. Open arrays are a solution... Answer: Object Pascal offers open arrays. A minimum function is a good example: function Min(const num: array of longint): longint; var x: longint; begin result := MaxLongInt; for x := low(num) to high(num) do if num[x] end; The const parameter means that the compiler makes no copy of the array but also allows no chances. The call: var a: longint; ... a := Min([3,6,2,8]);