Suppose I rather need to pick a map within a function at runtime. The code below which obviously fails compile, gives an idea of what I want to accomplish. Is there a way to create a local variable and initialize it to a map reference?
Code: Select all
Enumeration MapID
#MapOfStringsA = 1
#MapOfStringsB
#MapOfStringsC
EndEnumeration
Global NewMap MapOfStringsA.s()
Global NewMap MapOfStringsB.s()
Global NewMap MapOfStringsC.s()
Procedure GetMapRef(Map MapOfStrings.s())
ProcedureReturn @MapOfStrings()
EndProcedure
Procedure InitMap(MapID)
Protected *MapOfStrings, i=0
Select MapId
Case #MapOfStringsA
*MapOfStrings = GetMapRef(MapOfStringsA())
Case #MapOfStringsB
*MapOfStrings = GetMapRef(MapOfStringsB())
Case #MapOfStringsC
*MapOfStrings = GetMapRef(MapOfStringsC())
EndSelect
ForEach *MapOfStrings
i = i + 1
AddMapElement(*MapOfStrings(),"Key"+Str(i)
*MapOfStrings() = i
Next
ForEach *MapOfStrings()
Debug MapKey(*MapOfStrings())
Next
EndProcedure
Procedure main()
InitMap(#MapOfStringsA)
EndProcedure
main()