|
What
you have posted there won't compile.
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.
ie.
type
ArrayOfInt = array of Integer;
function GetMyInts: ArrayOfInt;
Now as
you have a dynamic array, you need to set the size.
Therefore you need
SetLength(result, 11);
then
your for loop would be
for i
:= 0 to 10 do
result[i] := i;
then
in a button event you could have something like
var
lIntArray: ArrayOnInt; i: Integer; begin lIntArray := GetMyInts; for i := 0 to High(lIntArray) do Listbox1.Items.Add(IntToStr(lIntArray[i])); // put items in a listbox end; Alternatively you could pass your array variable as a VAR
parameter.
Below
is some code to demostrate a function and procedure that can be
updated.
(Need
a Button and ListBox on a form)
type
ArrayOnInt = array of Integer; function GetMyInts: ArrayOnInt; overload;
var I: Integer; begin SetLength(result, 11); for i := 0 to 10 do result[i] := i; end; procedure GetMyInts(var aArray: ArrayOnInt); overload;
var I: Integer; begin SetLength(aArray, 11); for i := 0 to 10 do aArray[i] := i; end; procedure TForm3.Button1Click(Sender: TObject);
var lIntArray: ArrayOnInt; i: Integer; begin //lIntArray := GetMyInts; GetMyInts(lIntArray); for i := 0 to High(lIntArray) do Listbox1.Items.Add(IntToStr(lIntArray[i])); end; HTH,
JED
|
_______________________________________________ Delphi mailing list [EMAIL PROTECTED] http://ns3.123.co.nz/mailman/listinfo/delphi
