Board index » delphi » forward command

forward command

FORWARD command does'nt seem to work! if there is no other way to do it
then nevermind.

i will figure it out myself.

 

Re:forward command


In article <01bd03e1$7f8b4340$8b068bcd@computer>,

Quote
Arron Mitchell <ar...@nemaine.com> wrote:
>FORWARD command does'nt seem to work! if there is no other way to do it
>then nevermind.

Why don't you post the source that cause problems? Funny how nobody else
has found any problems with forward.

Quote

>i will figure it out myself.

Osmo

Re:forward command


Quote
> FORWARD command does'nt seem to work! if there is no other way to do it
> then nevermind.
> i will figure it out myself.

  The easiest way to circumvent forward is to declare a proc or func in a
units
interface section.
If forward is needed between units you will best define a variable
procedure
in a top unit:

Unit Types;   {the top most unit, called by all other units}

interface
Type AnyProcType = Procedure(abc:Integer; Var def:anytype);

implementation

Var AnyProc : AnyProcType;

Procedure DummyProc(abc:Integer; Var def:anytype); Far;
Begin  {do nothing}
End;

----
begin {Types initialisation}
   AnyProc := DummyProc; (* FOR SECURITY *)
end.
------------------------
Unit User2Unit;
interface
uses CRT,DOS,Types ... ;
implementation
Procedure LAnyProc(abc:Integer;Var def:anytype); Far;
Begin
   do any thing
End;
begin  {User2Unit initialisation}
   AnyProc := LAnyProc;
end.
This rather dirty trick is sometimes necessary, when idle procedures
or other hardware related jobs must be done, where otherwise the
units became circularly referenced.

Cheers, Franz Glaser http://members.eunet.at/meg-glaser

Re:forward command


Quote
"Arron Mitchell" <ar...@nemaine.com> wrote:
>FORWARD command does'nt seem to work! if there is no other way to do it
>then nevermind.

I pretty sure forward will work.  It might be some other
misunderstanding.  Post some actual code and point out where
you are having problems.  That will enable us to tailor a more
meaningful reply.  Could it possibly be you are trying to
include the function or procedure header w/ the 2nd declaration?
If so, don't.  If you wan't a copy of the header with the body
of the procedure then make it a comment.

BTW, you need to quote a little of the relevant parts of the
previous post so we can have a little context.  When you don't
quote and don't tie your response to the thread, it's like
entering into a group and resuming last week's conversation.

    ...red

--
Support the anti-Spam amendment
  Join at http://www.cauce.org/

Re:forward command


In article <34a447f7.97051...@news.southeast.net>,

Quote
R.E.Donais <rdon...@southeast.net> wrote:
>"Arron Mitchell" <ar...@nemaine.com> wrote:

>>FORWARD command does'nt seem to work! if there is no other way to do it
>>then nevermind.

>I pretty sure forward will work.  It might be some other
>misunderstanding.  Post some actual code and point out where
>you are having problems.  That will enable us to tailor a more
>meaningful reply.  Could it possibly be you are trying to
>include the function or procedure header w/ the 2nd declaration?
>If so, don't.  If you wan't a copy of the header with the body
>of the procedure then make it a comment.

No, don't make it a comment. In fact one should put the parameters also
in where the actual body is defined. That way the compiler can check
that you have identical definitions on both giving extra security. The
compiler does not check the comments.

Do you also leave the parameters out of the procedures and functions
that already are defined in the interface section of the unit? If not
then why not, as those analogous to procedures defined with forward.

Osmo

Re:forward command


Quote
ronka...@cc.helsinki.fi (Osmo Ronkanen) wrote:
>R.E.Donais <rdon...@southeast.net> wrote:
>>include the function or procedure header w/ the 2nd declaration?
>>If so, don't.  If you wan't a copy of the header with the body
>>of the procedure then make it a comment.

>No, don't make it a comment. In fact one should put the parameters also
>in where the actual body is defined. That way the compiler can check
>that you have identical definitions on both giving extra security. The
>compiler does not check the comments.

You're right!  Wasn't I surprised when it worked all the way
back to 1.0, and even with CP/M versions 1, 2, and 3!  Count
this as the new thing I learned today. ;-)

The only reason I can see why I've never listed the formal
parameters with the body of a forward declared procedure is
because the fine manuals (both TP 1.0 and 3.0) state:

 Forward References

   A subprogram is forward declared by specifying its
   heading separately from the block.  This separate
   subprogram heading is exactly as the normal heading,
   except that it is terminated by the reserved word
   forward.  The block follows later within the same
   declaration part.  Notice that the block is initiated
   by a copy of the heading, specifying only the name
   and no parameters, types, etc.

   Example:
     program Catch22;
     Var X: Integer;

     function Up(Var I: Integer): Integer; forward;

     function Down(Var I: Integer) : Integer;
     begin
        I := I div 2; Writeln(I);
        if I <> 1 then I := Up(I);
     end;

     function Up;
     begin
        ...

Seems I took the manual on blind faith, and since it worked, and
possibly because it's rarely used, I never took the opportunity
to experiment.  Can't remember, but even if I used forward after
TP 3.0, it never appeared on a list of differences between
versions, so I would never have changed.

Guess I'm just a persistent old goat.  :-)

Quote

>Do you also leave the parameters out of the procedures and functions
>that already are defined in the interface section of the unit?

Sometimes.  Like when maintaining a multi-version unit and
finding its much easier to comment than have to type a bunch of
IFDEF's a second time - argh!

    ...red

--
Support the anti-Spam amendment
  Join at http://www.cauce.org/

Other Threads