Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!think.com!hsdndev!cmcl2!adm!news From: CDCKAB%EMUVM1.BITNET@cunyvm.cuny.edu ( Karl Brendel) Newsgroups: comp.lang.pascal Subject: Re: Pointers to procedures Message-ID: <26505@adm.brl.mil> Date: 9 Apr 91 14:35:41 GMT Sender: news@adm.brl.mil Lines: 66 In article <9104081439.aa02828@VGR.BRL.MIL>, 209507097@ucis.vill.edu (MCREE, JAMES F) wrote: > I been following the thread of calling procedures by >pointers with a lot of interest recently. Mostly because I have an >application that is just begging for a solution like that. However, >the discussion and samples that I have seen (including those in the >manual) deal with hardcoding procedure names into the program. (ie. >Proc[i] := Do_It_Procedure) Is there a way of doing what my >syntactically incorrect program below is trying to do? > >Program Call_A_Variable_Procedure (Input,Output); >. >Var > Proc_Name : Procedure; >. >. >Assorted necessary delcarations >. >Begin >. >. >Assorted code statements >. >. >Write ('Enter the name of a procedure to run: '); >Readln (Proc_Name); >Proc_Name; >. >. >End. > > >This is an example of a user-specified call to a procedure. The >user specifies the procedure directly though. Can this be done? It isn't really apparent (to me) that your application is truly "begging for a solution like [pointers to procedures]". Why can you not just use a series of IF statements for your purpose? Proc_Name := stUpCase(Proc_Name); IF Proc_Name = 'PROC_A' THEN Proc_A ELSE IF Proc_Name = 'PROC_B' THEN ProcB etc.... Note that you may want to let the user specify arguments prior to calling the routine: Enter the name of a procedure to run (with arguments): proc_a(first_var, second_var)_ where the number of arguments may be different from routine to routine. I don't think there's any way of doing that with proceure types (or pointers thereto) which is really any more elegant or compact than the series of IF statements. (But that's probably shortsightedness on my part :) ) Cheers-- --Karl +--------------------------------------------------------------------+ | Karl Brendel Centers for Disease Control | | Internet: CDCKAB@EMUVM1.BITNET Epidemiology Program Office | | Bitnet: CDCKAB@EMUVM1 Atlanta GA 30093 USA | | Home of Epi Info 5.0 | +--------------------------------------------------------------------+