Passing back array from function 
Author Message
 Passing back array from function

Hi there,

Very new at writing functions in Pascal so I apologize if this question
is amateur. How do I pass back an array (dynamic or static) from a
function.

Tried this:

function DoWhatever( Input arguments) : array [0..3] of Real;

but it did not work.

Also, is it possible to pass back more then one variable from a function
without?

Thanks in advance!

Andrew Ross




Wed, 18 Jun 1902 08:00:00 GMT  
 Passing back array from function
well it's possible ,but it goes in a completely different way..

try this:

uses stuff;

type
  mytype:array [0..3] of real;

Function DoWhatever (input arguments): MyType;

---------
just define it with 'TYPE'


Quote:
>Hi there,

>Very new at writing functions in Pascal so I apologize if this question
>is amateur. How do I pass back an array (dynamic or static) from a
>function.

>Tried this:

>function DoWhatever( Input arguments) : array [0..3] of Real;

>but it did not work.

>Also, is it possible to pass back more then one variable from a function
>without?

>Thanks in advance!

>Andrew Ross





Wed, 18 Jun 1902 08:00:00 GMT  
 Passing back array from function

Quote:

> How do I pass back an array (dynamic or static) from a function.

> Tried this:

> function DoWhatever( Input arguments) : array [0..3] of Real;

> but it did not work.

A function result is by definition restricted to a single variable.
A String result is a non-standard extension by Turbo Pascal.

BUT: You can return a pointer as a function result.

On the other hand it seems not very reasonable for me to
explain you that here, when I estimate you skill...
So, please, use Var parameters within the parameter list of a
procedure (or function with a single-variable result) until you
learned more basics of Pascal.

Franz Glaser



Wed, 18 Jun 1902 08:00:00 GMT  
 Passing back array from function
On Thu, 28 Jan 1999 21:53:12 +0100, "The NightmarE"

Quote:

> try this:
> uses stuff;
> type
>   mytype:array [0..3] of real;

> Function DoWhatever (input arguments): MyType;

> ---------
> just define it with 'TYPE'

Please don't try this. It will give you a lot of errors at compile
time. Sometimes one should test code before posting it.

Borland Pascal cannot return arrays.

Regards
Horst



Wed, 18 Jun 1902 08:00:00 GMT  
 Passing back array from function


[sorry attribution lost when putting quoting in order]

Quote:
>>Also, is it possible to pass back more then one variable from a function
>>without?

Yes, very easily. If you define your parameters to the function as var
parameters you can pass results back to the original variables.

type
   mytype : array[0..3] of real;

var array1 : mytype;
var array2 : mytype;

Procedure DoSomething(var passed1, passed2 : mytype);

Then call the procedure with:
        DoSomething(array1,array2);

Quote:
>uses stuff;

>type
>  mytype:array [0..3] of real;

>Function DoWhatever (input arguments): MyType;

>---------
>just define it with 'TYPE'

Nope, he cannot do it this way. TP/BP does not allow other than the
predefined types to be returned from functions. You must use var
parameters as described above.

--
Pedt

This is the age of the train - it's about 107



Wed, 18 Jun 1902 08:00:00 GMT  
 Passing back array from function


Quote:
>well it's possible ,but it goes in a completely different way..

>try this:

>uses stuff;

>type
>  mytype:array [0..3] of real;

>Function DoWhatever (input arguments): MyType;

if you would have bothered to try that at home before posting
you would have figured that this does not work.
Quote:

>---------
>just define it with 'TYPE'



>>Hi there,

>>Very new at writing functions in Pascal so I apologize if this question
>>is amateur. How do I pass back an array (dynamic or static) from a
>>function.

>>Tried this:

>>function DoWhatever( Input arguments) : array [0..3] of Real;

>>but it did not work.

>>Also, is it possible to pass back more then one variable from a function
>>without?

>>Thanks in advance!

>>Andrew Ross





Wed, 18 Jun 1902 08:00:00 GMT  
 Passing back array from function


Quote:

> TP/BP does not allow other than the
>predefined types to be returned from functions.

Not quite so, IIRC; you cannot return structured types, but you can
return a string of any length, or an enumerated or subset type.

IIRC, Delphi allows return of structured types.

--

  Web <URL: http://www.merlyn.demon.co.uk/> - TP/BP/&c. FAQqish topics & links.
  Timo's TurboPascal <A HREF="ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip">FAQ</A>.
  <A HREF="http://www.merlyn.demon.co.uk/clpb-faq.txt">Mini-FAQ</A> of c.l.p.b.



Wed, 18 Jun 1902 08:00:00 GMT  
 Passing back array from function
in pascal a function can only return the basic pascal types
and not user defined types thus this is not possible the way
you try it. however you can do it with a pointer to an array like
this:

type
  ptr=^arr;
  arr=array[1..3] of integer;

function whatever(x,y,z:integer):ptr;
begin
 .....
end;

var
  p:ptr;
  a:integer;
begin
  p:=whatever(1,2,3);
  a:=p^[1];
end;

its quite easy.

Quote:

>Hi there,

>Very new at writing functions in Pascal so I apologize if this question
>is amateur. How do I pass back an array (dynamic or static) from a
>function.

>Tried this:

>function DoWhatever( Input arguments) : array [0..3] of Real;

>but it did not work.

>Also, is it possible to pass back more then one variable from a function
>without?

>Thanks in advance!

>Andrew Ross





Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. pass a pointer to a array to a function

2. Passing multidimensional arrays to functions/procedures

3. passing an array to a function

4. Passing Arrays to Procedures and Functions

5. Pass Functions into Function

6. Pass Functions into Function?

7. looping back to a specfic array element

8. problem passing array values.

9. Problems passing a field array as argument to InsertRecord

10. passing an array from an offset of the first element

11. Creating and passing Safe Arrays

12. passing variable sized arrays to a proc/func

 

 
Powered by phpBB® Forum Software