Board index » delphi » Passing parameters to and from libraries - HELP NEEDED

Passing parameters to and from libraries - HELP NEEDED

Unit YN;

Interface

Uses crt;

Procedure YorN (YN : char);{requests Yes or No otherwise ignores answer.}

Implementation

Procedure YorN (YN : char);

var yn_entered : boolean;

Begin
  yn_entered:=false;
  while not yn_entered do
  begin
    YN:= readkey;
    YN:= upcase (YN);
    if ((yn='Y') or (yn='N'))  then yn_entered:=true;
  End;                                 {while}
End;
End.

The above is a small unit I created - (YN.TPU)
When I run the following program I find the variable answer contains #0 (is this null)
can anyone explain why ?
I can't find any documentation for passing parameters to libraries in TP7 manual.

program YesOrNo;

Uses

yn,
crt;

VAR Answer : Char;

begin
  Writeln('Yes or No ?  ');
  yorn(answer);
  case answer of
   'Y' : writeln('Yes entered');
   'N' : writeln('No entered');
  end;{case}
  readln;
end.

 

Re:Passing parameters to and from libraries - HELP NEEDED


Quote
Mike Ridyard wrote:

> Unit YN;

> Interface

> Uses crt;

> Procedure YorN (YN : char);{requests Yes or No otherwise ignores
> answer.}

> Implementation

> Procedure YorN (YN : char);

> var yn_entered : boolean;

> Begin
>   yn_entered:=false;
>   while not yn_entered do
>   begin
>     YN:= readkey;
>     YN:= upcase (YN);
>     if ((yn='Y') or (yn='N'))  then yn_entered:=true;
>   End;                                 {while}
> End;
> End.

> The above is a small unit I created - (YN.TPU)
> When I run the following program I find the variable answer contains
> #0 (is this null)
> can anyone explain why ?
> I can't find any documentation for passing parameters to libraries in
> TP7 manual.

> program YesOrNo;

> Uses

> yn,
> crt;

> VAR Answer : Char;

> begin
>   Writeln('Yes or No ?  ');
>   yorn(answer);
>   case answer of
>    'Y' : writeln('Yes entered');
>    'N' : writeln('No entered');
>   end;{case}
>   readln;
> end.

You pass an empty variable (answer) to a procedure, which then finds a
value for another variable (yn) which you don't use. In other words, I
think you're using a procedure where you'd want to use a function.

Good luck,

Remco de Korte
Soft Machine / R.S.I.
http://www.xs4all.nl/~remcodek/

Re:Passing parameters to and from libraries - HELP NEEDED


---===>Quoting Mike Ridyard<===---

MR> Procedure YorN (YN : char);{requests Yes or No otherwise ignores
MR> answer.}

You should try Procedure YorN (var YN : char);

MR> Procedure YorN (YN : char);

Here too of course.

cu

Balazs Fischer

Balazs.Fisc...@studbox.uni-stuttgart.de
PGP Key: http://pgp5.ai.mit.edu:11371/pks/lookup?op=get&search=0xED7447E5
Fingerprint: 8F EF C0 BA 22 B4 15 B3  56 27 07 04 37 7B D6 00
Encrypted mail prefered

... Let me know right away if you don't get this message.

Re:Passing parameters to and from libraries - HELP NEEDED


Mike Ridyard heeft geschreven in bericht
<67k0fp$98...@taliesin.netcom.net.uk>...

Quote
>Unit YN;

>Interface

>Uses crt;

>Procedure YorN (YN : char);{requests Yes or No otherwise ignores answer.}

>Implementation

>Procedure YorN (YN : char);

>var yn_entered : boolean;

>Begin
>  yn_entered:=false;
>  while not yn_entered do
>  begin
>    YN:= readkey;
>    YN:= upcase (YN);
>    if ((yn='Y') or (yn='N'))  then yn_entered:=true;
>  End;                                 {while}
>End;
>End.

>The above is a small unit I created - (YN.TPU)
>When I run the following program I find the variable answer contains #0 (is
this null)
>can anyone explain why ?
>I can't find any documentation for passing parameters to libraries in TP7
manual.

>program YesOrNo;

>Uses

>yn,
>crt;

>VAR Answer : Char;

>begin
>  Writeln('Yes or No ?  ');
>  yorn(answer);
>  case answer of
>   'Y' : writeln('Yes entered');
>   'N' : writeln('No entered');
>  end;{case}
>  readln;
>end.

It would be more logic if you made it a function which returns Y or N.
But if you want to do it this way, you should implement VAR in the procedure
statement like:

Procedure YorN (VAR YN : char);

That should do the trick. but as stated before a function would make more
sence.

Regards
Bas

Re:Passing parameters to and from libraries - HELP NEEDED


Quote

>Procedure YorN (VAR YN : char);

>That should do the trick. but as stated before a function would make more
>sence.

>Regards
>Bas

It works, It works, "A Thousand Thank-you's"

(One simple omission and the whole program is Kaputt.)

Other Threads