Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-08

Local procedures as actual procedure parameter in macpas mode

12 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author
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

Jonas Maebe
to Unknown author
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

Alberto Narduzzi
to Unknown author: Trying to compile the following code (porting from MW Pascal) type myObject = object…
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.
Jonas Maebe
to Alberto Narduzzi
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.

Show quoted text 6 lines
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

Alberto Narduzzi
to Jonas Maebe

Jonas,

Show quoted text 7 lines
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.
Jonas Maebe
to leledumbo
leledumbo wrote 5 lines
> 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

Marco van de Voort
to Jonas Maebe

In our previous episode, Jonas Maebe said:

Show quoted text 7 lines
>> 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).

leledumbo
to Marco van de Voort

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

Marco van de Voort wrote 19 lines
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 - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
View this message in context: http://old.nabble.com/Local-procedures-as-actual-procedure-parameter-in-macpas-mode-tp29524474p29563939.html Sent from the Free Pascal - General mailing list .
Marco van de Voort
to leledumbo

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.

leledumbo
to Marco van de Voort

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 21 lines
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 - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
View this message in context: http://old.nabble.com/Local-procedures-as-actual-procedure-parameter-in-macpas-mode-tp29524474p29568863.html Sent from the Free Pascal - General mailing list .
Adriaan van Os
to Marco van de Voort: In our previous episode, leledumbo said: They pretty much started the recent quo vadis…
Marco van de Voort wrote 13 lines
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