I think is better without global variables...
Code: Select all
DeclareModule TestLibrary
Declare SetGgtDefault(Txt.s = "", GgtX.i = #PB_Ignore, GgtY.i = #PB_Ignore, GgtWidth.i = #PB_Ignore, GgtHeight.i = #PB_Ignore)
Declare CreateGgt(GgtID.i, Txt.s = "", GgtX.i = #PB_Ignore, GgtY.i = #PB_Ignore, GgtWidth.i = #PB_Ignore, GgtHeight.i = #PB_Ignore)
EndDeclareModule
Module TestLibrary
Structure udtBtnDefault
BtnText.s
BtnX.i
BtnY.i
BtnWidth.i
BtnHeight.i
EndStructure
Global BtnDefault.udtBtnDefault
Procedure InitModule()
With BtnDefault
\BtnText = "Button"
\BtnX = 10
\BtnY = 10
\BtnWidth = 100
\BtnHeight = 30
EndWith
EndProcedure : InitModule()
Procedure SetGgtDefault(Txt.s = "", GgtX.i = #PB_Ignore, GgtY.i = #PB_Ignore, GgtWidth.i = #PB_Ignore, GgtHeight.i = #PB_Ignore)
With BtnDefault
If Txt <> "" : \BtnText = Txt : EndIf
If GgtX <> #PB_Ignore : \BtnX = GgtX : EndIf
If GgtY <> #PB_Ignore : \BtnY = GgtY : EndIf
If GgtWidth <> #PB_Ignore : \BtnWidth = GgtWidth : EndIf
If GgtHeight <> #PB_Ignore : \BtnHeight = GgtHeight : EndIf
EndWith
EndProcedure
Procedure CreateGgt(GgtID.i, Txt.s = "", GgtX.i = #PB_Ignore, GgtY.i = #PB_Ignore, GgtWidth.i = #PB_Ignore, GgtHeight.i = #PB_Ignore)
With BtnDefault
If Txt = "" : Txt = \BtnText : EndIf
If GgtX = #PB_Ignore : GgtX = \BtnX : EndIf
If GgtY = #PB_Ignore : GgtY = \BtnY : EndIf
If GgtWidth = #PB_Ignore : GgtWidth = \BtnWidth : EndIf
If GgtHeight = #PB_Ignore : GgtHeight = \BtnHeight : EndIf
EndWith
GID = ButtonGadget(GgtID, GgtX, GgtY, GgtWidth, GgtHeight, Txt)
ProcedureReturn GID
EndProcedure
EndModule
; =========================== TEST
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(0, 0, 0, 400, 100, "Module Gadgets", wFlags)
UseModule TestLibrary
;use the module's default values
CreateGgt(1)
;change the module's global position
SetGgtDefault("", 120, 10)
CreateGgt(2, "Button 2")
;change the module's global size & caption
SetGgtDefault("Button 3", #PB_Ignore, #PB_Ignore, 160, 40)
CreateGgt(3, "", 230, 50)
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend