<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2180" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff size=2>What
you have posted there won't compile.</FONT></SPAN></DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff size=2>For
starters you can't return an Array of Integer from a function you must make a
new type that is array of integer and return that.</FONT></SPAN></DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff
size=2>ie.</FONT></SPAN></DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff
size=2>type</FONT></SPAN></DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff size=2>
ArrayOfInt = array of Integer;</FONT></SPAN></DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff
size=2>function GetMyInts: ArrayOfInt;</FONT></SPAN></DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff size=2>Now as
you have a dynamic array, you need to set the size.</FONT></SPAN></DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff
size=2>Therefore you need</FONT></SPAN></DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff
size=2>SetLength(result, 11); </FONT></SPAN></DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff size=2>then
your for loop would be</FONT></SPAN></DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff size=2>for i
:= 0 to 10 do</FONT></SPAN></DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff size=2>
result[i] := i;</FONT></SPAN></DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff size=2>then
in a button event you could have something like</FONT></SPAN></DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff
size=2>var<BR> lIntArray: ArrayOnInt;<BR> i:
Integer;<BR>begin<BR> lIntArray := GetMyInts;<BR> for i := 0 to
High(lIntArray) do<BR>
Listbox1.Items.Add(IntToStr(lIntArray[i])); // put items in a
listbox<BR>end;</FONT></SPAN></DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff
size=2>Alternatively you could pass your array variable as a VAR
parameter.</FONT></SPAN></DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff size=2>Below
is some code to demostrate a function and procedure that can be
updated.</FONT></SPAN></DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff size=2>(Need
a Button and ListBox on a form)</FONT></SPAN></DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff
size=2>type<BR> ArrayOnInt = array of Integer;</FONT></SPAN></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff
size=2>function GetMyInts: ArrayOnInt; overload;<BR>var<BR> I:
Integer;<BR>begin<BR> SetLength(result, 11);<BR> for i := 0 to 10
do<BR> result[i] := i;<BR>end;</FONT></SPAN></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff
size=2>procedure GetMyInts(var aArray: ArrayOnInt); overload;<BR>var<BR>
I: Integer;<BR>begin<BR> SetLength(aArray, 11);<BR> for i := 0 to 10
do<BR> aArray[i] := i;<BR>end;</FONT></SPAN></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff
size=2>procedure TForm3.Button1Click(Sender: TObject);<BR>var<BR>
lIntArray: ArrayOnInt;<BR> i: Integer;<BR>begin<BR> //lIntArray :=
GetMyInts;<BR> GetMyInts(lIntArray);<BR> for i := 0 to
High(lIntArray) do<BR>
Listbox1.Items.Add(IntToStr(lIntArray[i]));<BR>end;<BR></FONT></SPAN></DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff
size=2>HTH,</FONT></SPAN></DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff
size=2>JED</DIV></FONT></SPAN>
<DIV><SPAN class=318214602-07122004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma
size=2>-----Original Message-----<BR><B>From:</B> Paul McKenzie
[mailto:paul@smss.org.nz]<BR><B>Sent:</B> 7 December 2004 1:20
PM<BR><B>To:</B> Delphi List - Delphi<BR><B>Subject:</B> [DUG] Returning Open
Arrays<BR><BR></FONT></DIV>
<DIV><FONT face=Arial size=2>How do I Build and Return an Open
Array</FONT></DIV>
<DIV><FONT face=Arial size=2>I know I can do this with a TList or other means
- but seems over the top...</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>eg</FONT></DIV>
<DIV><FONT face=Arial size=2>function GetMyInts: Array of
Integer;</FONT></DIV>
<DIV><FONT face=Arial size=2>var</FONT></DIV>
<DIV><FONT face=Arial size=2> I: Integer;</FONT></DIV>
<DIV><FONT face=Arial size=2>begin</FONT></DIV>
<DIV><FONT face=Arial size=2> for I := 0 to 10
do</FONT></DIV>
<DIV><FONT face=Arial size=2> Result :=
Result + I;</FONT></DIV>
<DIV><FONT face=Arial size=2>end;<BR></DIV></FONT>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Regards<BR>Paul McKenzie<BR>SMSS
Ltd.<BR>Wellington<BR>New Zealand</FONT></DIV></BLOCKQUOTE></BODY></HTML>