Wrappers

[quote=492609:@Clifford Coulter]Exactly!

What should the parameters look like for this function:

Function get(index as Integer) as string
return self.theArray(index)
end Function

Maybe: (index as Integer) as string.
Not sure about that.[/quote]

parameters are the parts in between the ()
the return type is the trailing “as string” where you would, in the IDE, just put “string”

[quote=492613:@Norman Palardy]parameters are the parts in between the ()
the return type is the trailing “as string” where you would, in the IDE, just put “string”[/quote]

So set the return type as string and the parameters as index as Integer is what it means.

Yes.

I wanted to thank you for the wrapper exercise yesterday Norman. I now believe I better understand how they can work. The constructor used was very informative.

I do have another question:

I am bringing open a window that needs to first load in an array from a Hard drive file and set some properties. The controls then must use these properties to determine what file info they must be set to. As it is now the properties are not set in time so the slider controls which use the properties do not get set when the controls open. Would a construct be the answer? I believe it would need to be in a class but I’m not sure if it would be a class made just for it.

The Constructor method is called automatically when a class instance is instantiated via the New operator. If instantiation requires some data, that data is passed to the constructor method via parameters. You can have multiple Constructor methods, each with a different number or different types of parameters, to cover different methods of instantiation. Whichever constructor matches the parameters you pass is the one that will be executed. If there is no constructor matching the parameters you pass, a compiler error will be generated.

[quote=492862:@Clifford Coulter]
I am bringing open a window that needs to first load in an array from a Hard drive file and set some properties. The controls then must use these properties to determine what file info they must be set to. As it is now the properties are not set in time so the slider controls which use the properties do not get set when the controls open. Would a construct be the answer? I believe it would need to be in a class but I’m not sure if it would be a class made just for it.[/quote]

A constructor would work for this
Note however that in order to USE that constructor you would have to manually create the window instead of relying on implicit instances. This means this window also could not be used as the startup window for the app.

Both of those mechanisms would not use your new constructor amd would only use one that has no parameters

I am not looking to pass any parameters to the window or constructor in this case but need to load array data from a hard drive before anything else happens when the window opens. The Heating window I created is not the main window but the data loaded off the drive which I hope can be before the window opens needs to set sliders etc when the window opens. I created a method and called it constructor and tried to place it in two locations to see if it would be seen. The first was a method in the window and another I placed in a class thinking it needed to be in a class to fire. Neither did. I believe I’m missing something.

if you already know everything and dont need parameters then a constructor with no parameters would work
and you could still use it as the app default since that expects a no parameter constructor
as do implicit instances

[quote=492975:@Norman Palardy]if you already know everything and dont need parameters then a constructor with no parameters would work
and you could still use it as the app default since that expects a no parameter constructor
as do implicit instances[/quote]

I’m not sure what you mean by app default, I thought that is in the main window. I’m attempting to pace the constructor someplace in another window that opens that I use to set times, days, zones, temperatures for heating requirements. I was thining the constructor needs to be in that window.

Click on the App instance in the left hand navigator
Then make sure the inspector is showing in the right hand side
You should see there is a spot for “Default Window”
I mean THAT window - the one the App opens start start up by default without you having to write any code

we’re probably using different names for the same thing

Sure - in whatever window you need this data to be set BEFORE the open events of the controls runs

I now see I have a choice to start up in any window which is good to know but not what I need. I need to access the Heating Preference Window from a menu selection which then opens and loads the stored prefs from the hard drive to set the sliders in that window. I was trying to find a way to get those values off the drive in a way that they would set the sliders in the window when it opened. Last time I did this I loaded those pref off the HD and passed them to the window when it was to open. I thought I might be able to make the Heating Prefs Window a little more self-contained and have it fetch its values for the sliders that I use to set temps, times, etc.

you could still [quote]… loaded those pref off the HD and passed them to the window [/quote] but pass the m to it as part of the constructor for that window
that way the values are there before the sliders run their open events (which you previously was an issue)

Yes, I started an about face this morning and am tying to send Arrays (may be a pointer since I do not remember how that works) this:

Normal_Heating_Preference_Window.constructor(Arrays)

But the constructor method is not firing in the Normal_Heating_Preference_Window.

Not sure why!

Start with trying this
In the Navigator click on Normal_Heating_Preference_Window
In the inspector turn OFF implicit instance
And then try & run and see what issues this shows

Implicit instance relies on having and using a constructor that has NO paramaters
Its seductively easy but once you have it turned on and rely on it then try to do stuff like this and need thigns to work differently implicit instances can be a liability

[quote=493038:@Clifford Coulter]Yes, I started an about face this morning and am tying to send Arrays (may be a pointer since I do not remember how that works) this:
Normal_Heating_Preference_Window.constructor(Arrays)
[/quote]

Since I dont know what the arrays are, types etc the best I can offer is general advice
Suppose you want to pass in an array of strings
Then the constructor would look like

Sub Constructor( stringArray() as string )
end sub

and you would create a new instance of this window like

 dim newPrefsWindow as New Normal_Heating_Preference_Window( theArrayParameterIAmTryingToPassIn)

Note you CANNOT use implicit instances with this constructor
Make sure Normal_Heating_Preference_Window has implicit instance set to FALSE (off)

And this may reveal places where your code depends on it being on

[quote=493038:@Clifford Coulter]
But the constructor method is not firing in the Normal_Heating_Preference_Window.
Not sure why![/quote]

Really depends on how you instantiate it

Do a breakpoint and debugger away.

I read NormaN_Heating_Preference_Window.constructor(Arrays).

This sounds like the type of stuff that is normally done in the Open event of a window. No need to bother with constructors at all, unless I’m missing something.

When I turned off implicit instance I received this error:

There is more than one method with this name but this does not match any of the available signatures.
Normal_Heating_Preference_Window.constructor(Arrays)

What I had done before, which worked was to:

Place this Preference, “Arrays” in the App Preferences as type ArrayHolderClass. The ArrayHolderClass held all my arrays and some methods for loading the prefs from the HD.

Next:

Arrays = new ArrayHolderClass
Arrays.LoadDataArrays

Then I sent the class (which could be by ref, I’m not sure) to :

Normal_Heating_Preference_Window.constructor(Arrays)

I’m questioning why I needed to add “.constructor(Arrays)”. I thought the constructor in the window method sshould fire on its own when I called the window. Is this True or false?

https://forum.xojo.com/conversation/post/492862

he’d have to rewrite how his window opens and move all the code for the open events of the controls as well

a constructor would make it possible to avoid having to do that

[quote=493053:@Clifford Coulter]
I’m questioning why I needed to add “.constructor(Arrays)”. I thought the constructor in the window method sshould fire on its own when I called the window. Is this True or false?[/quote]

My questions is how do you “call the Window” ?

With a constructor you need to have code like

dim w as new Normal_Heating_Preference_Window.constructor(Arrays)

somewhere

Okay, team, you have beaten me into submission and put me back on the high road. First of all, I’m such a XOJO neophyte that I didn’t realize you might want to or could create a new instance of a window. I thought you just opened them with show. Now that’s probably funny to most of you but not to me.

This was the answer to my misguide reasoning:

dim w as new Normal_Heating_Preference_Window(Arrays)

Which fired my constructor that made life good again. The array holder class reference was sent and the sliders in the window are as happy as clams at high tide.

Please don’t abandon me “Team”, all of you were extremely helpful and I understand a few more things. I am a bit slow but I’m consistent. I’ll make it eventually!

[quote=493065:@Clifford Coulter]Okay, team, you have beaten me into submission and put me back on the high road. First of all, I’m such a XOJO neophyte that I didn’t realize you might want to or could create a new instance of a window. I thought you just opened them with show. Now that’s probably funny to most of you but not to me.
[/quote]
A very common misunderstanding becuase most windows start out with implicit instance enabled
And as long as you only want to use single instances of these then its usually not a problem
But as soon as you need to step away from that in any way then there’s this learning curve

[quote=493065:@Clifford Coulter]
This was the answer to my misguide reasoning:

dim w as new Normal_Heating_Preference_Window(Arrays)

Which fired my constructor that made life good again. The array holder class reference was sent and the sliders in the window are as happy as clams at high tide.

Please don’t abandon me “Team”, all of you were extremely helpful and I understand a few more things. I am a bit slow but I’m consistent. I’ll make it eventually![/quote]

Now there IS one issue with this you need to be aware of
You can / could open 10 of those windows using this style - that may or may not be a problem