Share this page 

Overload a global functionTag(s): Powerscript


thanks to Lawrence Sims for the following tip

You can overload global function objects in PowerBuilder with a simple trick. Just always edit them in source view, not in the painter. The following function (f_log) can be called like so:

f_log("Message To Be Logged")
f_log(t_throwable_caught, populateError (0, ""))
f_log(populateError(0, "Got to here ...")) 
[f_log.srf]
just imported this file into a PBL to be able to use the overloaded f_log function)
global type f_log from function_object
end type
 
type prototypes
subroutine OutputDebugString (string as_msg) library "kernel32.dll" &
   alias for "OutputDebugStringA"
end prototypes
 
forward prototypes
global subroutine f_log (readonly string as_msg)
global subroutine f_log (throwable at, readonly integer ai_nu)
global subroutine f_log (readonly integer ai_nu)
end prototypes
 
global subroutine f_log (readonly string as_msg);
OutputDebugString (as_msg)
end subroutine

global subroutine f_log (throwable at, readonly integer ai_nu);
string ls_message
 
ls_message = error.text
if isNull (error.text) or error.text = "" &
   then ls_message = at.getMessage ()
 
OutputDebugString (error.object + "." + error.objectevent + &
                   ": line " + string (error.line) + ": " + ls_message)
end subroutine
 
global subroutine f_log (readonly integer ai_nu);
if isValid (error) then
 OutputDebugString (error.object + "." + error.objectevent + &
                    ": line " + string (error.line) + ": " + error.text)
end if
end subroutine