Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!paperboy!hsdndev!cmcl2!adm!news From: 209507097@ucis.vill.edu (MCREE, JAMES F) Newsgroups: comp.lang.pascal Subject: Pointers to procedures Message-ID: <26525@adm.brl.mil> Date: 10 Apr 91 20:08:49 GMT Sender: news@adm.brl.mil Lines: 47 Karl Brendel writes... >>I don't know much about Procedure Pointers in PASCAL, but I can see >>one way in which this becomes truly elegant. >> >>Define an array of Procedure Pointers. This, in conjuction with a >>numerical or key-letter input reduces to a mapping function (for >>key-letters) and a single call ProcPtrVar[Choice]; > >True, but the original question involved accepting a character >_string_ naming the procedure (although e-mail has revealed that >what the poster really _wants_ is a menu pick). Also this solution >doesn't allow for passing parameters to procedures unless they all >take the same sequence of parameters (same quantity, order and >type). (E-mail has also revealed that the poster does want varying >sequences of parameters.) That's not quite what I had in mind. The user picks a menu choice which calls a procedure whose name is specified in an input file. Consider the following file: 1 Do_Operation_One (Some params) 2 Do_A_Different_Op (A few other params) 3 The_Final_Solution (All params) My goal was to read in a menu file (use the above as an example). If the user entered a 1 to a prompt, procedure "Do_Operation_One (Some params)" would be called. Likewise for a 2 and 3. Initially, this does not present a problem. Here's the problem. Let's say we want to make this a generic menu unit which will have the capability of calling any procedure so long as its name is specified in an input file. The name of the procedures would be read and if its number came up, it would be called. All of this ideally should be done without the need to recompile the menu unit. The solution that I have ended up falling back to was a simple giant case statement because the procedures will have params that will not all be the same. I'm still interested in the idea of calling a procedure whose name is specified by an input file entry without parameters though. A series of IF statements might work equally as well, but would probably end up being longer if I were to stick to structured programming. Thanks for all of the ideas. There are still a bunch of them that I would like to play with and see how useful they will be in other areas. Have a good day, Jim.