ParamArray of Pair in share method

I have a function like this created as a shared method of a class:

Public Shared Function toDictionary(ParamArray entries As Pair) as dictionary

Calling it like this, gives me a “This item does not exists” compiler error.

dim d as dictionary = myclass.toDictionary("name":"Joe", "v1":10)

Yet same function as global or as an instance method works.

Any suggestions!

Using: Xojo 2019 R 3.1, Mac OS Catalina

Should be ParamArray entries() As Pair

@Jose Cuevas — What strikes me with Xojo 2019 is that many error messages are not even remotely related to the actual error. As such, “This item does not exist” may be related to a syntax error, a hidden Unicode character somewhere etc…

It did not work using ParamArray entries() As Pair still get same message.

As in my original post, I put the exact same code as a global function or a class instance method and it works. But not in a shared method.

After testing a bit I tried other shared methods using ParamArray and they do not work on this class. I copied the shared method to another class and it works.

My class name is “types” is a class with helper shared methods and others, manly use to help me bridge data types from Xojo/iOS framework to traditional API.

I found that non of the shared methods work when used from a window event or control (any). But moving the call outside the ui works:

//in module tests
Public Sub callSharedMethod()
  //this works

  types.test1("name", "jose")
End Sub

In a from PushButton action

Sub Action() Handles Action
   callSharedMethod //this works!
   // var s as string = types.uid()   //gives error
   //types.test1("name", "jose")   //gives error
End Sub

So the issue is the class name “types”, I searched the docs for “types” to see if there was something in the global scope or similar, but all I found was this enumeration: “Window.Types”, but my impression is that “types” is scoped as verified with this code:

dim t as variant = window.types.Document //this work as expected
dim t as variant = types.Document //this doesnt work as expected

I dont know what im doing wrong or what’s the obscure scope resolution that the compiler is doing, but at least I know to use a different approach.

Thanks all for your help…

Types you need other class name or add a Module and put (drag) the Class below.

1.
MyTypes
(the constructor mentioned in docu with entries did not work …)

[code]Public Shared Function toDictionary(ParamArray entries As Pair) as Dictionary

Var d As New Dictionary

For Each p As Pair In entries
d.Value(p.Left) = p.Right
Next

Return d

End Function
[/code]

Test in Window Open Event

[code]Var d As Dictionary = MyTypes.toDictionary(New Pair(“A”,“B”),New Pair(“C”,“D”))

Var j As JSONItem

j = d

System.DebugLog j.ToString[/code]

2. in the ide it looks like Module1.Classes.Types

screenshot (self deleted after 1 month)

[code]Var d As Dictionary = Module1.Types.toDictionary(New Pair(“A”,“B”),New Pair(“C”,“D”))

Var j As JSONItem

j = d

System.DebugLog j.ToString[/code]

[quote=492257:@Jose Cuevas]I have a function like this created as a shared method of a class:

Public Shared Function toDictionary(ParamArray entries As Pair) as dictionary

Calling it like this, gives me a “This item does not exists” compiler error.

dim d as dictionary = myclass.toDictionary("name":"Joe", "v1":10)

Yet same function as global or as an instance method works.

Any suggestions!

Using: Xojo 2019 R 3.1, Mac OS Catalina[/quote]

Do you call it like:

Var d as dictionary = ClassWithSharedMethod.toDictionay("entry":"value")

Then it should just work without an instance.

That’s not required.

the problem will be used names by xojo.
i tested it even with the name “Types”

Thanks for your suggestion, indeed like I posted anything that adds a scope like you mention putting the class in a module or changing the class name works in a window.

The name of the class “types” is what causes the conflict when used inside a window o control, everywhere else it works as expected.

The problem has nothing to do with ParramArray or the use of pair. The scope resolution is resolving “types” to something else in a window/control.

less conflicts but longer names.