Board index » delphi » VAR in proc header fails

VAR in proc header fails

Hi all.

very simply, calls to the following procedure FAIL to pass the value of
rad to the procedure calc_elipse.

In Tpascal, I am sure this would work fine!

procedure calc_elipse(VAR ix, iy, deg : Integer;   rad, align, offset :
Integer);

ideas welcome, cheers   Jim

remove s from swandana to email reply

Jim Barr        Machine Conversation
                http://www.wandana.demon.co.uk/
                Best is the enemy of good enough
                Leaves rustle,   blades turn,    water moves

Barrs Law of Recursive futility:---
        If you are smart enough to use one of these.....
                       .....you can probably manage without one!

 

Re:VAR in proc header fails


Bet ya $1,000 (US) that it does work. The following ultrasophisticated
test proves it.

procedure calc_elipse(VAR ix, iy, deg : Integer;   rad, align, offset :
Integer);
begin
  messagedlg ('Rad is ' + inttostr(rad), mtInformation, [mbOK],
    0);
end;

procedure TForm1.Button1Click(Sender: TObject);
var a,b,c : integer;
begin
 a := 1; b := 2; c := 3;
 calc_elipse(a,b,c,4,5,6);
end;

Quote
Jim Barr wrote:

> Hi all.

> very simply, calls to the following procedure FAIL to pass the value of
> rad to the procedure calc_elipse.

> In Tpascal, I am sure this would work fine!

> procedure calc_elipse(VAR ix, iy, deg : Integer;   rad, align, offset :
> Integer);

> ideas welcome, cheers   Jim

> remove s from swandana to email reply

> Jim Barr        Machine Conversation
>                 http://www.wandana.demon.co.uk/
>                 Best is the enemy of good enough
>                 Leaves rustle,   blades turn,    water moves

> Barrs Law of Recursive futility:---
>         If you are smart enough to use one of these.....
>                        .....you can probably manage without one!

--

Robert

To send me E-Mail, remove removethis. from my E-Mail address.

Re:VAR in proc header fails


On Wed, 18 Jun 1997 21:40:40 +0100, Jim Barr

Quote
<jimb...@wandana.demon.co.uk> wrote:
>Hi all.
>very simply, calls to the following procedure FAIL to pass the value of
>rad to the procedure calc_elipse.

>In Tpascal, I am sure this would work fine!

>procedure calc_elipse(VAR ix, iy, deg : Integer;   rad, align, offset :
>Integer);

>ideas welcome, cheers   Jim

There's nothing obviously wrong with the procedure declaration, how
about sending some of the calling code so's we can get some context?

Quote
>remove s from swandana to email reply

>Jim Barr        Machine Conversation
>                http://www.wandana.demon.co.uk/
>                Best is the enemy of good enough
>                Leaves rustle,   blades turn,    water moves

>Barrs Law of Recursive futility:---
>        If you are smart enough to use one of these.....
>                       .....you can probably manage without one!

Regards,

Stephen Posey
slpo...@concentric.net

Beware of Geeks bearing GIFs!

Re:VAR in proc header fails


In article <33a8b007.21253...@news.concentric.net>, Stephen Posey
<slpo...@concentric.net> writes

Quote
>On Wed, 18 Jun 1997 21:40:40 +0100, Jim Barr
><jimb...@wandana.demon.co.uk> wrote:

>>Hi all.
>>very simply, calls to the following procedure FAIL to pass the value of
>>rad to the procedure calc_elipse.

>>In Tpascal, I am sure this would work fine!

>>procedure calc_elipse(VAR ix, iy, deg : Integer;   rad, align, offset :
>>Integer);

>>ideas welcome, cheers   Jim

>There's nothing obviously wrong with the procedure declaration, how
>about sending some of the calling code so's we can get some context?

>>remove s from swandana to email reply

>>Jim Barr        Machine Conversation
>>                http://www.wandana.demon.co.uk/
>>                Best is the enemy of good enough
>>                Leaves rustle,   blades turn,    water moves

>>Barrs Law of Recursive futility:---
>>        If you are smart enough to use one of these.....
>>                       .....you can probably manage without one!

>Regards,

>Stephen Posey
>slpo...@concentric.net

>Beware of Geeks bearing GIFs!

Hi Stephen and thanks,

Here is the whole procedure and the calling one. As you may guess I only
need to return SOME of the parameters, hence breaking the VAR half way

[ Section: 1/1 File: elipse.txt Encoder: Turnpike Version 3.03a ]

begin 644 elipse.txt
<uuencoded_portion_removed>
0#0H@(&EX("`@("`Z/2!X7P``
`
end

sum -r/size 65345/3029 section (from "begin" to "end")
sum -r/size 58416/2176 entire input file

This code is VERY experimental hence all the commenting out.  IF I put
in default values for the rad parameter in the Calc_Elipse routine, the
whole thing functions correctly.

Is there some difference between VAR in pascal and delphi?

Cheers, jim

remove s from swandana to email reply

Jim Barr        Machine Conversation
                http://www.wandana.demon.co.uk/
                Best is the enemy of good enough
                Leaves rustle,   blades turn,    water moves

Barrs Law of Recursive futility:---
        If you are smart enough to use one of these.....
                       .....you can probably manage without one!

Re:VAR in proc header fails


Quote
Jim Barr wrote:

> Hi all.

> very simply, calls to the following procedure FAIL to pass the value of
> rad to the procedure calc_elipse.

> In Tpascal, I am sure this would work fine!

> procedure calc_elipse(VAR ix, iy, deg : Integer;   rad, align, offset :
> Integer);

> ideas welcome, cheers   Jim

> remove s from swandana to email reply

> Jim Barr      

Your question is ambiguous.  Your header says that "VAR fails", which
implies that you want to pass rad as a VAR, not as a value.  However,
your message text says that the procedure "FAIL to pass the value of rad
...".  I am assuming that you really want to pass the address of rad,
not its value, to the procedure, so that the procedure can update rad
for you -- that's what "var" parameters are for.

The problem is that the effect of "var" terminates at the next
semicolon, in order to allow you to have a mixed list of var and value
parameters. If you want to pass "rad" as a var parameter, you need to
write "var rad ..." instead of just "rad ...", and then the last three
parameters will all be var parameters, also.

--
Howard L. Kaplan
Psychopharmacology and Dependence Research Unit
Women's College Hospital
76 Grenville Street, 9'th floor
Toronto, Ontario
Canada  M5S 1B2
(416)323-6400, ext 4915
howard.kap...@utoronto.ca

Re:VAR in proc header fails


On Thu, 19 Jun 1997 20:21:53 +0100, Jim Barr

Quote
<jimb...@wandana.demon.co.uk> wrote:

[deletia]

Quote
>Hi Stephen and thanks,

>Here is the whole procedure and the calling one. As you may guess I only
>need to return SOME of the parameters, hence breaking the VAR half way

I think I may have found your problem; the procedure is declared like
so:

procedure calc_elipse(VAR ix,iy,deg : Integer;
  rad, align, offset : Integer);

but you call it in the code you sent like so:

calc_elipse(ix,iy,radius,degree, align, offset);

My guess is that you mean for the actual parameters "degree" and
"radius" to map to the formal parameters "rad" and "deg", but you have
them reversed; maybe try:

calc_elipse(ix,iy,degree, radius, align, offset);

Could this be the source of the problem?

?????

Stephen Posey
slpo...@concentric.net

Beware of Geeks bearing GIFs!

Re:VAR in proc header fails


In article <33A96504.3...@utoronto.ca>, Howard Kaplan
<howard.kap...@utoronto.ca> writes

Quote
>Jim Barr wrote:

>> Hi all.

>> very simply, calls to the following procedure FAIL to pass the value of
>> rad to the procedure calc_elipse.

>> In Tpascal, I am sure this would work fine!

>> procedure calc_elipse(VAR ix, iy, deg : Integer;   rad, align, offset :
>> Integer);

>> ideas welcome, cheers   Jim

>> remove s from swandana to email reply

>> Jim Barr      

>Your question is ambiguous.  Your header says that "VAR fails", which
>implies that you want to pass rad as a VAR, not as a value.  However,
>your message text says that the procedure "FAIL to pass the value of rad
>...".  I am assuming that you really want to pass the address of rad,
>not its value, to the procedure, so that the procedure can update rad
>for you -- that's what "var" parameters are for.

>The problem is that the effect of "var" terminates at the next
>semicolon, in order to allow you to have a mixed list of var and value
>parameters. If you want to pass "rad" as a var parameter, you need to
>write "var rad ..." instead of just "rad ...", and then the last three
>parameters will all be var parameters, also.

This is all too embarrasing, I gad called the procedure with the
parameters in a differrent order!

That is why it was failing

Sorry folks and thanks for the attention!

Cheers, Jim

remove s from swandana to email reply

Jim Barr        Machine Conversation
                http://www.wandana.demon.co.uk/
                Best is the enemy of good enough
                Leaves rustle,   blades turn,    water moves

Barrs Law of Recursive futility:---
        If you are smart enough to use one of these.....
                       .....you can probably manage without one!

Re:VAR in proc header fails


In article <33a9e297.6891...@news.concentric.net>, Stephen Posey
<slpo...@concentric.net> writes

Quote
>On Thu, 19 Jun 1997 20:21:53 +0100, Jim Barr
><jimb...@wandana.demon.co.uk> wrote:

>[deletia]

>>Hi Stephen and thanks,

>>Here is the whole procedure and the calling one. As you may guess I only
>>need to return SOME of the parameters, hence breaking the VAR half way

>I think I may have found your problem; the procedure is declared like
>so:

>procedure calc_elipse(VAR ix,iy,deg : Integer;
>  rad, align, offset : Integer);

>but you call it in the code you sent like so:

>calc_elipse(ix,iy,radius,degree, align, offset);

>My guess is that you mean for the actual parameters "degree" and
>"radius" to map to the formal parameters "rad" and "deg", but you have
>them reversed; maybe try:

>calc_elipse(ix,iy,degree, radius, align, offset);

>Could this be the source of the problem?

>?????

Yes Stephen, I feel a total idiot, I found the error as soon as I had
broadcast the problem to the whole world!

Thanks for the guidance!

Jim

remove s from swandana to email reply

Jim Barr        Machine Conversation
                http://www.wandana.demon.co.uk/
                Best is the enemy of good enough
                Leaves rustle,   blades turn,    water moves

Barrs Law of Recursive futility:---
        If you are smart enough to use one of these.....
                       .....you can probably manage without one!

Re:VAR in proc header fails


Jim Barr <jimb...@wandana.demon.co.uk> wrote in article
<eQ7jrJAoZrqzE...@wandana.demon.co.uk>...

Quote
> Yes Stephen, I feel a total idiot, I found the error as soon as I had
> broadcast the problem to the whole world!

welcome to the world of famous red faces!

One of the reasons for using classes & objects is that
in general, the number of arguments to functions is
reduced, and the problem of mixing arguments is
also reduced.
--
Grace + Peace   *   Peter N Roth  *   Engineering Objects International
Author of "C++ Jump Start" ISBN 0-9655862-2-7.
Tools for Developers: ClassBuilder 4 for Delphi, ClassBuilder++ for C++
Visit our website at http://www.inconresearch.com/eoi

Re:VAR in proc header fails


Quote
In article <eQ7jrJAoZrqzE...@wandana.demon.co.uk> Jim Barr <jimb...@wandana.demon.co.uk> writes:
>Yes Stephen, I feel a total idiot, I found the error as soon as I had
>broadcast the problem to the whole world!
>Thanks for the guidance!

:-)  You're not the first to do it, Jim, and you certainly won't be the last
one to do it.  Happy Friday!  ;-)

Other Threads