Local procedures as actual procedure parameter in macpas mode

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Local procedures as actual procedure parameter in macpas mode

fpanasiti@tiscali.it
Trying to compile the following code (porting from MW Pascal)
        type  
       
myObject = object
                procA (x: integer);
                procC (procedure procD (var
y: myObject));
        end;
        procedure  myObject. procC (procedure procD (var
y: myObject));
        begin
                procD (y);
                {more code here ...}
        end;
       
procedure myObject.ProcA (x: integer);
                procedure ProcB (var y:
myObject);
                begin
                        {some code here ...}
                end;
        begin
                procC
(ProcB);
        end;

I get the following error:
 - Got "myObject.ProcB (var
myObject) is nested;", expected "<procedure variable type of procedure
(var myObject) is nested;Register>"
Apparently the compiler is
considering ProcB to be a method of myObject (which is not the case, as
it is not included in the object definition), thus I'm wondering if it
comes from a wrong syntax I'm using .
Thanks in advance for any help.


Regards
Francesco Panasiti


Risparmia con Tutto Incluso Light: telefono + adsl 8 mega a soli 19,95 € al mese per un anno!

SCONTO DI 120 EURO!

http://abbonati.tiscali.it/telefono-adsl/prodotti/tc/tuttoincluso_light/?WT.mc_id=01fw
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Local procedures as actual procedure parameter in macpas mode

Jonas Maebe-2

On 24 Aug 2010, at 19:29, [hidden email] wrote:

> Trying to compile the following code (porting from MW Pascal)
[snip]

It's fixed. When reporting problems in the future, please include full source code instead of only snippets.


Jonas

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Local procedures as actual procedure parameter in macpas mode

Alberto Narduzzi
In reply to this post by fpanasiti@tiscali.it
> Trying to compile the following code (porting from MW Pascal)
> procC (procedure procD (var y: myObject));

the compiler is complaining because the ProcB is a nested procedure of
ProcA.

Try defining it outside the object, if possible.
If not, define it as an object method(*)

I also suggest you do

Type TMyProc Procedure(var y:myObject);
(*) in case of an object method, I think you must add "Of Object" at the
end of its declaration.

it makes all more readable on first instance.

Just my 2c

Cheers, A.

--
Alberto Narduzzi
ANSware Ltd.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Local procedures as actual procedure parameter in macpas mode

Jonas Maebe-2

On 24 Aug 2010, at 22:38, Alberto Narduzzi wrote:

>> Trying to compile the following code (porting from MW Pascal)
>> procC (procedure procD (var y: myObject));
>
> the compiler is complaining because the ProcB is a nested procedure of ProcA.

No. He's using MacPas mode in FPC 2.5.1. In that mode, nested procedural variables are supported (and also in ISO mode, and also in all other syntax modes if you add {$modeswitch nestedprocvars}). The error message was caused by a compiler bug.

> I also suggest you do
>
> Type TMyProc Procedure(var y:myObject);
> (*) in case of an object method, I think you must add "Of Object" at the end of its declaration.
>
> it makes all more readable on first instance.

This declares a regular procvar, while the original declaration declares a nested procvar. Declaring it as a separate type would have to be done like this:

Type TMyProc Procedure(var y:myObject) is nested;

Note that you can assign both global and nested/local procedures to a nested procedural variable (and also call both using such a procvar). And be careful when using a separate "is nested" type, because then you can construct code that calls a nested procedural variable outside the scope where it is valid (which will result in undefined behaviour).


Joans_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Local procedures as actual procedure parameter in macpas mode

Alberto Narduzzi
Jonas,

> No. He's using MacPas mode in FPC 2.5.1. In that mode, nested procedural variables are supported (and also in ISO mode, and also in all other syntax modes if you add {$modeswitch nestedprocvars}). The error message was caused by a compiler bug.
>
> This declares a regular procvar, while the original declaration declares a nested procvar. Declaring it as a separate type would have to be done like this:
>
> Type TMyProc Procedure(var y:myObject) is nested;
>
> Note that you can assign both global and nested/local procedures to a nested procedural variable (and also call both using such a procvar). And be careful when using a separate "is nested" type, because then you can construct code that calls a nested procedural variable outside the scope where it is valid (which will result in undefined behaviour).


thanks for the explanation, I didn't know all this. I don't use nested
procedures as parameters, so from the error message I just assumed they
weren't allowed.

Cheers, A.


--
Alberto Narduzzi
ANSware Ltd.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Local procedures as actual procedure parameter in macpas mode

leledumbo
Administrator
> In that mode, nested procedural variables are supported (and also in ISO mode, and also in all other syntax modes if you add {$modeswitch nestedprocvars})

FPC has ISO mode?
Reply | Threaded
Open this post in threaded view
|

Re: Local procedures as actual procedure parameter in macpas mode

Jonas Maebe-2

On 28 Aug 2010, at 06:50, leledumbo wrote:

>> In that mode, nested procedural variables are supported (and also in ISO
>> mode, and also in all other syntax modes if you add {$modeswitch
>> nestedprocvars})
>>
> FPC has ISO mode?

Since a few weeks, yes. It's only ISO Standard Pascal though, no Extended Pascal.


Jonas_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Local procedures as actual procedure parameter in macpas mode

Marco van de Voort
In our previous episode, Jonas Maebe said:
> >> In that mode, nested procedural variables are supported (and also in ISO
> >> mode, and also in all other syntax modes if you add {$modeswitch
> >> nestedprocvars})
> >>
> > FPC has ISO mode?
>
> Since a few weeks, yes. It's only ISO Standard Pascal though, no Extended Pascal.

And Std I/O doesn't work yet. (filedescriptor^, get, put).

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Local procedures as actual procedure parameter in macpas mode

leledumbo
Administrator
It could be a good start. Have you invited GPC people to contribute?

Marco van de Voort wrote
In our previous episode, Jonas Maebe said:
> >> In that mode, nested procedural variables are supported (and also in ISO
> >> mode, and also in all other syntax modes if you add {$modeswitch
> >> nestedprocvars})
> >>
> > FPC has ISO mode?
>
> Since a few weeks, yes. It's only ISO Standard Pascal though, no Extended Pascal.

And Std I/O doesn't work yet. (filedescriptor^, get, put).

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Local procedures as actual procedure parameter in macpas mode

Marco van de Voort
In our previous episode, leledumbo said:
>
> It could be a good start. Have you invited GPC people to contribute?

They pretty much started the recent quo vadis threads excluding any form of
merger/cooperation with FPC.  

The second message of Frank in that thread contains:
( http://www2.gnu-pascal.de/crystal/gpc/en/mail14684.html )

.... all I'll say WRT my participation in any project with
FPC is: Not interested.

So I guess nobody bothered.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Local procedures as actual procedure parameter in macpas mode

leledumbo
Administrator
Well, OK. Looks like it's not yet the time for the two Pascal communities to unite. Maybe when GPC really dies... (hasn't it?)

Marco van de Voort wrote
In our previous episode, leledumbo said:
>
> It could be a good start. Have you invited GPC people to contribute?

They pretty much started the recent quo vadis threads excluding any form of
merger/cooperation with FPC.  

The second message of Frank in that thread contains:
( http://www2.gnu-pascal.de/crystal/gpc/en/mail14684.html )

.... all I'll say WRT my participation in any project with
FPC is: Not interested.

So I guess nobody bothered.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Local procedures as actual procedure parameter in macpas mode

Adriaan van Os-2
In reply to this post by Marco van de Voort
Marco van de Voort wrote:

> In our previous episode, leledumbo said:
>> It could be a good start. Have you invited GPC people to contribute?
>
> They pretty much started the recent quo vadis threads excluding any form of
> merger/cooperation with FPC.  
>
> The second message of Frank in that thread contains:
> ( http://www2.gnu-pascal.de/crystal/gpc/en/mail14684.html )
>
> .... all I'll say WRT my participation in any project with
> FPC is: Not interested.
>
> So I guess nobody bothered.

I will note that this is the private opinion of Frank Heckenbach (only).

Regards,

Adriaan van Os

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal