function to read an array of doubles into a string variable

Posted on 2006-06-28
Last Modified: 2010-04-05
hi there experts!!!!!

i have an array. i call it myarray(). this is an array of doubles.this is a static has just two elements.

e.g myarray(0)=2,34

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;
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

urgent help needed

thanks  a lot
Question by:nikolaosk
  • 2
LVL 14

Accepted Solution

Pierre Cornelius earned 250 total points
ID: 17000250
function readarrayofdoublesinasting (const arr : array of doubles) :String;
var n : integer;
  result:= '';
  for n := low(arr) to high(arr)
    do result:= result + FloatToStr(arr[n])+',';
  SetLength(result, length(result)-1); //get rid of last comma
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 17000257
type: "array of doubles"
should be "array of double"
LVL 10

Expert Comment

ID: 17000290
I suggest

  MyPoint = record
    X : Double;
    Y : Double;
  MyResult = record
    Str1, Str2 : String;

function myfunc(myarray : array of MyPoint) : MyResult;
  i : integer;
  For i := low(myarray) to high(myarray) do
    Result.Str1 := Result.Str1 + ',' + FloatToStr(myarray[i].X);
    Result.Str2 := Result.Str2 + ',' + FloatToStr(myarray[i].Y);
  SetLength(Result.Str1, length(Result.Str1)-1);
  SetLength(Result.Str2, length(Result.Str2)-1);

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
IExtractImage Delphi 14 207
ddeman not working in activex 3 93
Delphi XE10 Round Image 2 79
How to convert memory stream to PDF file 6 20
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now