### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: Help about dynamic array function  (Read 1503 times)

#### TRon

• Hero Member
• Posts: 536
##### Re: Help about dynamic array function
« Reply #15 on: August 09, 2020, 12:59:03 pm »
Got it, this is my first time posting, thanks for the reminder !
I have no idea what gave it away but I somehow suspected it was your first post ... perhaps it was the postcount ?

But, no worries. That is why I try to put you on the right track so that you know for next time.

I also got a question, how i use it outside ?
You got several options but the basics is the same. Your function returns an array of type int_a.

Code: Pascal  [Select][+][-]
1. var
2.   ret: int_a;
3.
4. begin
5.   // 1. store the value to a "local" one
6.   ret := max_s_to_a_of_int('1_22_333');
7.   // and provide that as "input" for the next function
8.   a_input(ret);
9.
10.   // 2. do it as you showed, directly.
11.   a_input(max_s_to_a_of_int('1_22_333'));
12. end.
13.
However, do not forget that the "input type" for a_input should also be of type int_a. Pascal uses strong typing.

#### TRon

• Hero Member
• Posts: 536
##### Re: Help about dynamic array function
« Reply #16 on: August 09, 2020, 01:41:21 pm »
Oops, I forgot to address a particular question you asked

do i use it like a[n], n = integer within low(a)..high(a) inside the function ?
Yes, that is perfectly fine to do inside your function. Even stronger, that is the preferred way of doing it.

Besides that you can also use for ... in construct to iterate a dynamic array.

This is my take on your input_a() (I made it a) procedure, since it did not seem to me as if it should return anything.
Code: Pascal  [Select][+][-]
1. procedure input_a(arr: t_dynamic_long_integer_array);
2. var
3.   v: longint;
4.   i: sizeint;
5. begin
6.   // approach 1, using for ... in
7.   for v in arr
8.     do writeln('value=',v);
9.   writeln;
10.
11.   // approach 2, using low(array) to high(array)
12.   for i:= low(arr) to high(arr)
13.     do writeln('value=',arr[i]);
14.   writeln;
15. end;
16.