關於全局自定義函數的重載現象

最近在上網看些實例的時候,發現我們自已自定義的全局函數一個好玩的重載現象.
一般我們如果要對函數進行重載,則會定義多個相同名稱的函數,只是參數定義會不一樣,如果是全局函數,因為名稱都相同,而在一個PBL中不允許有同名的
對象存在,所以不能定義.而實際上PB提供了另一個未公開的方法可以實現.
如先定義一個全局函數,名稱為of_tt,無返回值,腳本為:messagebox('a','ok').
存檔后,使用Edit Source功能查看其原碼:
global type of_tt from function_object
end type

forward prototypes
global subroutine of_tt ()
end prototypes

global subroutine of_tt ();
messagebox('a', 'ok')
end subroutine

如果需要對此函數進行重載,則可以自己在此Source View畫面中直接添加腳本即可.
如我將其修改為:
global type of_tt from function_object
end type

forward prototypes
global subroutine of_tt ()
global subroutine of_tt (readonly string as_tip)
end prototypes

global subroutine of_tt ();
messagebox('a', 'ok')
end subroutine

global subroutine of_tt (readonly string as_tip);
messagebox('a', as_tip)
end subroutine

這樣同一個函數就有兩種不同的使用方式.
那我們在其它地方可以依如下方法調用:
of_tt()
of_tt('This is a Test.')

 

你可能感兴趣的:(關於全局自定義函數的重載現象)