Page 1 of 1

Some functions should return the previously used value

Posted: Sun Mar 10, 2013 12:39 pm
by codeprof
Functions like DrawingMode,DrawingFont,CustomFilterCallback,FrontColor and BackColor should return the previously used value.
This could help to create more generic custom drawing commands, because we could set them back to the original value.

This would be also very handy for OnErrorCall. However there it is not that easy, because there are different possiblilites (OnErrorCall, OnErrorDefault,OnErrorExit or OnErrorGoto).
Therefore we would need an additional command like e.g. GetOnErrorType()...

Re: Some functions should return the previously used value

Posted: Thu Aug 29, 2013 2:23 pm
by Little John
Agreed.

I've written my own wrapper OnErrorCallEx():

Code: Select all

Procedure.i OnErrorCallEx (*proc)
   ; in : address of the new      error handling procedure
   ; out: address of the previous error handling procedure
   Static *prev
   
   OnErrorCall(*proc)
   Swap *prev, *proc
   ProcedureReturn *proc
EndProcedure


;=========== How to use OnErrorCallEx() ===========

Procedure GeneralErrorHandler()
   ; [...]
EndProcedure

OnErrorCallEx(@GeneralErrorHandler())

;--------------------------------------------------

Procedure SpecialErrorHandler()
   ; [...]
EndProcedure

Procedure Demo()
   Protected *prevErrHandler = OnErrorCallEx(@SpecialErrorHandler())
   
   ; [...]
   
   If *prevErrHandler <> #Null
      OnErrorCallEx(*prevErrHandler)
   EndIf
EndProcedure
Similar wrappers can be written for the other functions under consideration. However, it would be much more elegant if this functionality would be built into PB.
So +1 from me.