` Printed Icetips Article

Icetips Article



Clarion in general: Passing procedures as parameters
2006-02-10 -- Larry Sand
 
Here's a trivial example of "how" you would use a procedure as a prototype.
It's difficult to come up with a non-trivial example using this technique.
It's more appropriate where you want to allow access to some data from
within a compiled module.  A virtual method is very simlar and a better
choice in many circumstances.  For a real world example of how a callback is
used in the Windows API, look in comp.lang.clarion for a thread with the
subject enumfonts.  I posted an example on 2006.19.01 that uses a typed
procedure to prototype the callback procedure passed to the windows API.
Another similar example is the FileCallbackInterface in Clarion.

HTH,

Larry Sand
---------------------------

  Program
  Map
TranslatorCallbackProc  Procedure(Long MsgId),Type
Translate     Procedure(TranslatorCallbackProc TraslateMessageId, Long MsgId)

enTranslator  Procedure(Long MsgId)
esTranslator  Procedure(Long MsgId)
  End

nMsg  Long
  Code

  nMsg = 1
  Translate(enTranslator, nMsg)
  nMsg = 2
  Translate(esTranslator, nMsg)


Translate Procedure(TranslatorCallbackProc TraslateMessageId, long MsgId)
  Code
  TraslateMessageId(MsgId)
  Return



enTranslator Procedure(Long MsgId)
  Code
  Case MsgId
  Of 1
    message('Hello')
  Of 2
    message('Goodbye')
  End
  Return

esTranslator Procedure(Long MsgId)
  Code
  Case MsgId
  Of 1
    message('Hola')
  Of 2
    message('AdiĆ³s')
  End
  Return



Printed November 23, 2024, 6:09 pm
This article has been viewed/printed 35288 times.
Google search has resulted in 18 hits on this article since January 25, 2004.