<!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.2800.1458" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Thanks -I'll go with the var option...</FONT></DIV>
<DIV> </DIV>
<DIV>Regards<BR>Paul McKenzie<BR>SMSS Ltd.<BR>Wellington<BR>New Zealand</DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=JeremyN@frontiersoftware.com.au
href="mailto:JeremyN@frontiersoftware.com.au">JeremyN@frontiersoftware.com.au</A>
</DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=delphi@ns3.123.co.nz
href="mailto:delphi@ns3.123.co.nz">delphi@ns3.123.co.nz</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Tuesday, December 07, 2004 3:51
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> RE: [DUG] Returning Open
Arrays</DIV>
<DIV><BR></DIV>
<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>
<P>
<HR>
<P></P>_______________________________________________<BR>Delphi mailing
list<BR>Delphi@ns3.123.co.nz<BR>http://ns3.123.co.nz/mailman/listinfo/delphi<BR></BLOCKQUOTE></BODY></HTML>