Google Answers Logo
View Question
 
Q: Programming in Delphi 3: passing the whole array ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: Programming in Delphi 3: passing the whole array
Category: Computers > Programming
Asked by: cyntlhiadiane-ga
List Price: $5.00
Posted: 07 Oct 2003 12:26 PDT
Expires: 06 Nov 2003 11:26 PST
Question ID: 263545
I want to pass an array to another procedure in Delphi 3.  How do I
type the parameter list?
var
AccountNumber : array [1..100] of variant;
AccountType : array[1..100] of variant;
// Loop through the array and fill with values
// Now call the procedure and pass the array

Create_the_Record(AccountNumber,AccountType);

It's the parameter list for this last part that I am not typing correctly.
Answer  
Subject: Re: Programming in Delphi 3: passing the whole array
Answered By: joseleon-ga on 07 Oct 2003 13:02 PDT
Rated:5 out of 5 stars
 
Hello, cyntlhiadiane:

  To pass an array to a procedure it's better to use open array
parameters, take a look at this code:

procedure MyProcedure(items: array of integer);
var
    i:integer;
begin
    for i:=low(items) to high(items) do begin
        showmessage(inttostr(items[i]));
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
    values: array [1..10] of integer;
begin
    myprocedure([1,2,3]);
    myprocedure(values);
end;

In the line:

    myprocedure([1,2,3]);
    
You are constructing an array of integers to be passed to the
function, but in the line:

    myprocedure(values);
    
you are passing a fixed size array, the key is in the declaration of
the parameters here:

procedure MyProcedure(items: array of integer);

and the way you use them to know the lowest element and the highest
element:

    for i:=low(items) to high(items) do begin
    
Feel free to request any clarification until you understand how they
behave.

Regards.
cyntlhiadiane-ga rated this answer:5 out of 5 stars and gave an additional tip of: $1.00
Simple enough for me to follow and comprehend.  Exact information that I needed.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy