Path: utzoo!attcan!uunet!wuarchive!zaphod.mps.ohio-state.edu!think.com!hsdndev!cmcl2!adm!news From: RCIVDAB%HDETUD1.TUDELFT.NL@uga.cc.uga.edu ( Dim Biesheuvel) Newsgroups: comp.lang.pascal Subject: Re: procedures as parameters to procedures Message-ID: <25855@adm.brl.mil> Date: 6 Feb 91 10:26:17 GMT Sender: news@adm.brl.mil Lines: 69 On Tue, 29 Jan 91 11:26:31 EST cliff said: > >hi, > we run vs pascal 2.1 on vm/sp 6. is it possible to pass as a procedure > parameter a procedure name with a parameter list? for example, > >program main (input,output); > >var word: packed array(1..5) of char; > >procedure abc(procedure xyx(var string: packed array(1..5) of char);i:integer); > . > . >procedure blah(var string: packed array(1..5) of char); > . > . > begin (* main program *) > . > . > abc(blah(word),3) > end. > >i can pass procedure names without parameter lists as parameters to a >procedure, but i get errors using the above code. i don't know if this >is a restriction on our particular product or not. the pascal report >(wirth & jensen) seems to indicate you can do this. does anyone have an >example of code where this has been successfully done? any help is >appreciated. > Well Cliff, I don't know if others answered your question already, but I'll try anyway. You can pass a procedure as a parameter, that's true, but what you are trying to do is passing a procedure call as a parameter. Now I don't know what that should mean. If instead of a procedure a function was called at the activation of abc, yes, that would have a meaning for me. The function call would yeald a result and that value would be passed to the corresponding parameter, a value parameter of the same type as the function. But what should happen now at the call of abc? Do you want to happen blah first? Or do you want to be able to call blah from somewhere in abc. Well, in that case you just pass blah, without parameters, in the procedure call of abc, and if you want to call blah with an argument from your main program, you'll have to pass that argument as well. So you'll have rewrite abc as follows: Type string5 = packed array (. 1..5 .) of char; procedure abc ( procedure xyz ( str : string5 ); pqr : string5; i : integer); ... begin ... xyz ( pqr ); ... end; and abc would be called as abc ( blah, word, 3 ); Some remarks: 1. As in a parameter specification only a TypeIdentifier is allowed you'll have to introduce a TypeIdentifier for your string variable. 2. A packed variable can only be passed as a value parameter. I hope this helps. Dim