Passing a window reference to a function

I am writing a Settings Class, which can store various settings to a file.
I know, this has been done before. And there are many different ways of doing it.

The class stores the settings in a dictionary (the new framework style). It saves the data on disk in the JSON format.
The different value types I can read and write are Integer, Text, String (the classic one), Folderitem (classic & new framework), Color, Boolean and Date. More are coming soon.
Two value types I am working on now are WindowPos and WindowSize. The method I am calling is:

Sub WindowPosSet(fieldname as text, WindowRef as window)
  Dim Top as Integer = WindowRef.top
  Dim Left as Integer = WindowRef.left

  dim txt as Text = Left.ToTextr + "," + Top.ToText
  // code to store the value in the dictionary 
End Sub

My problem is that when I call this method, an error is raised.

Parameter "WindowRef" expects type Window, but this is class Window1.Window1

I call this method when Window1 is moved. I refer to this window with Self

In another method I use the same parameters, and use the reference WindowRef to set the Left and Top values.
Same error there.

Strange, here, calling that method with

WindowPosSet("", self)

triggers no error.

I use this kind of parameter a lot in RubberViews and never observed the issue you describe. Are you sure this is all the code ?

Yes, this is all the code.

The problem is that when I use this method, I use self. And the class I am passing it on to is expecting a Window type. Now it somehow sees it as some kind of subclass, I think. But shouldn’t it be seen as a window?

[quote=210942:@Edwin van den Akker]Yes, this is all the code.

The problem is that when I use this method, I use self. And the class I am passing it on to is expecting a Window type. Now it somehow sees it as some kind of subclass, I think. But shouldn’t it be seen as a window?[/quote]

If you call your method the same way I do, I see no reason whatsoever for the error you report.

I told you my RubberViews class does that intensively with no error of any kind, as well a test project I created from your posted code, and the problem does not exist. There must be something else in your project.

In full despair, you may try to cast your window, but I frankly do not see why you should have to :

WindowPosSet("Whatever text", Window(self))

I, too, pass windows like that all the time without error. There is something else going on in your code.

Yeah, It never happened before. Casting the window actually worked. Thanks

This is my test project.

No error here if in Moved I go :

cfg.FieldWindowPositionSet "window pos", self

Which version of Xojo are you using, on which platform ?

[quote=210969:@Michel Bujardet]No error here if in Moved I go :

cfg.FieldWindowPositionSet "window pos", self

Which version of Xojo are you using, on which platform ?[/quote]

I am on a Mac (latest OS-X 10.10.5)
Xojo 2015 r2.4

And very very very curious about Xojo 2015 r3

Same configuration, no error.

But if casting works, fine. If it does not do anything more, it does not hurt either.

As for R3, I am sure it will be great :wink: