nikolaosk
asked on
function to read an array of doubles into a string variable
hi there experts!!!!!
i have an array. i call it myarray(). this is an array of doubles.this is a static array.it has just two elements.
e.g myarray(0)=2,34
myarry(1)=34,5
the values of the array are x,y coordinates that represent a point which happens to be the center of a circle.
i need a function in delphi that will loop through the items of this array and will store its values in a string variable
something like this
function readarrayofdoublesinasting (const arr : array of doubles) :String;
var n : integer;
begin
for n := low(arr) to high(arr) do
//here loop through the items of the array
result := (str1,str2)
//where str1 and str2 are the x,y coordinates converted into a comma delimited string
end;
end;
urgent help needed
thanks a lot
i have an array. i call it myarray(). this is an array of doubles.this is a static array.it has just two elements.
e.g myarray(0)=2,34
myarry(1)=34,5
the values of the array are x,y coordinates that represent a point which happens to be the center of a circle.
i need a function in delphi that will loop through the items of this array and will store its values in a string variable
something like this
function readarrayofdoublesinasting
var n : integer;
begin
for n := low(arr) to high(arr) do
//here loop through the items of the array
result := (str1,str2)
//where str1 and str2 are the x,y coordinates converted into a comma delimited string
end;
end;
urgent help needed
thanks a lot
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I suggest
type
MyPoint = record
X : Double;
Y : Double;
end;
MyResult = record
Str1, Str2 : String;
end;
function myfunc(myarray : array of MyPoint) : MyResult;
var
i : integer;
begin
For i := low(myarray) to high(myarray) do
begin
Result.Str1 := Result.Str1 + ',' + FloatToStr(myarray[i].X);
Result.Str2 := Result.Str2 + ',' + FloatToStr(myarray[i].Y);
end
SetLength(Result.Str1, length(Result.Str1)-1);
SetLength(Result.Str2, length(Result.Str2)-1);
end;
type
MyPoint = record
X : Double;
Y : Double;
end;
MyResult = record
Str1, Str2 : String;
end;
function myfunc(myarray : array of MyPoint) : MyResult;
var
i : integer;
begin
For i := low(myarray) to high(myarray) do
begin
Result.Str1 := Result.Str1 + ',' + FloatToStr(myarray[i].X);
Result.Str2 := Result.Str2 + ',' + FloatToStr(myarray[i].Y);
end
SetLength(Result.Str1, length(Result.Str1)-1);
SetLength(Result.Str2, length(Result.Str2)-1);
end;
should be "array of double"