Some functions should return the previously used value

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
codeprof
User
User
Posts: 65
Joined: Sun Sep 16, 2012 12:13 pm

Some functions should return the previously used value

Post 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()...
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Some functions should return the previously used value

Post 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.
Post Reply