|
Jon has already alluded to the fact that the standard use procedure pointers only gives the illusion of dynamic procedure calls. In other words the procedure call is dynamic only in the sense that it points to a procedure whose address was resolved at compile time or when the program was activated in the case of a service pgm, unlike the old dynamic calls that are resolved only at runtime. It means that you can benefit by coding a call using a procedure pointer but you still have to include code that initializes all the pointers by assigning them the address of the corresponding procedure. So you are in effect still hard coding all the procedure calls. To obtain a truly dynamic procedure call that is not known at compile time you must you the special API's that permit you to force the activation of a service pgm and provide access to the procedures within. Cheers, Peter -----Original Message----- From: Scott Klement [mailto:klemscot@klements.com] Sent: Tuesday, December 05, 2000 12:23 PM To: RPG400-L@midrange.com Subject: Re: OO in RPG On Mon, 4 Dec 2000, Jim Langston wrote: > Please give me an example of a procedural pointer's use. Or reference to > where I can read about them. > > Regards, > Jim Langston Here's an example that I dreamed up of using a procedure pointer. Hopefully this illustrates their use fairly well :) (The only places that I've used procptr's in the past have been VERY complex programs, and wouldnt make good examples...) Let me know if it makes sense :) ** Procedure Pointer Example ** ** This example illustrates a dynamic decision of how to display ** a program's status messages to a user, or to the job log in ** case we wanted to be a batch program. ** ** D p_ShowProc S * ProcPtr D ShowMsg PR ExtProc(p_ShowProc) D Msg 50A const D StatMsg PR D Msg 50A const D DiagMsg PR D Msg 50A const D DsplyMsg PR D Msg 50A const D* API error code data structure D dsEC DS D dsECBytesP 1 4B 0 INZ(256) D dsECBytesA 5 8B 0 INZ(0) D dsECMsgID 9 15 D dsECReserv 16 16 D dsECMsgDta 17 256 D SndPgmMsg PR ExtPgm('QMHSNDPM') D MessageID 7A Const D QualMsgF 20A Const D MsgData 32766A options(*varsize) const D MsgDtaLen 10I 0 Const D MsgType 10A Const D CallStkEnt 10A Const D CallStkCnt 10I 0 Const D MessageKey 4A D ErrorCode 32766A options(*varsize) ** Normally, the users preference of how they want their messages ** displayed would come from a file containing user prefs, but ** to make the example simple, I'm just using a parm: ** C *entry plist c parm MsgType 7 c select c when MsgType = '*STATUS' c eval p_ShowProc = %paddr('STATMSG') c when MsgType = '*DIAG' c eval p_ShowProc = %paddr('DIAGMSG') c when MsgType = '*DSPLY' c eval p_ShowProc = %paddr('DSPLYMSG') c endsl ** Now you might have many, many lines of code, with occasional ** messages back to the user here and there... of course, to ** keep the example simple, I'm just going to send a simple ** test message, here... :) c callp ShowMsg('This is a test message.') c eval *inlr = *on P*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ P* This displays a message as a '*STATUS' message... P*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ P StatMsg B export D StatMsg PI D Msg 50A const D MsgKey S 4A c callp SndPgmMsg('CPF9897': 'QCPFMSG *LIBL': c Msg: 50: '*STATUS': '*EXT': 0: MsgKey: c dsEC) P E P*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ P* This puts a diagnostic message into the job log P*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ P DiagMsg B export D DiagMsg PI D Msg 50A Const D MsgKey S 4A c callp SndPgmMsg('CPF9897': 'QCPFMSG *LIBL': c Msg: 50: '*DIAG': '*': 0: MsgKey: dsEC) P E P*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ P* This shows a message using RPG's DSPLY op-code P*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ P DsplyMsg B export D DsplyMsg PI D Msg 50A Const c Msg dsply P E +--- | This is the RPG/400 Mailing List! | To submit a new message, send your mail to RPG400-L@midrange.com. | To subscribe to this list send email to RPG400-L-SUB@midrange.com. | To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: david@midrange.com +--- This communication is confidential and may be legally privileged. If it is not addressed to you, you are on notice of its status. Please immediately contact us at our cost and destroy it. Please do not use, disclose, copy, distribute or retain any of it without our authority - to do so could be a breach of confidence. Thank you for your co-operation. Please contact us on (09) 356 5800 if you need assistance. +--- | This is the RPG/400 Mailing List! | To submit a new message, send your mail to RPG400-L@midrange.com. | To subscribe to this list send email to RPG400-L-SUB@midrange.com. | To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: david@midrange.com +---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.