I tried searching for an answer but found none. Is there a technical reason why methods that use “Extends” must be in a module? The reason I ask is I want to create some extends functions very specific to a certain window, and it would make more sense to contain these methods in that window instead of being global to the entire project. I also may want to use a variation of these methods on different windows, but not have to use different method names (easier code reuse).
So, is there some technical limitation in the IDE or compiler? Or is this just how Xojo designed it?
I believe that’s just how it was designed. Extends are meant to be global. I have tried to do exactly what you want in the past too. Not sure if there’s a Feedback request to allow local extends or not.
[quote=485517:@Norman Palardy]1) they have to exist at all times
2) they have to be global[/quote]
Ok, but why?[quote=485518:@Bob Keeney]Not sure if there’s a Feedback request to allow local extends or not.[/quote]
There’s not (that I found), which is why I was asking here first before submitting a Feedback that won’t be possible.
[quote=485519:@Jay Madren]Ok, but why?
There’s not (that I found), which is why I was asking here first before submitting a Feedback that won’t be possible.[/quote]
As far as I know because they relate to a type and types are global symbols (even if you stuff it in a module etc the compiler looks up and finds it based on the fully qualified name)
Thats based on what I gleaned from years of working with Joe & Aaron and could well be mistaken
You’d really need to ask Joe or Aaron or Mars though
Or Xojo’s current compiler engineer if they’ll reply here about this
First, to everyone, I am only interested in methods that take an “Extends x As String” parameter as I said at the beginning. I’m not trying to extend classes. I don’t want to get into the reason I need them to be extends as opposed to regular methods right now.
The interface option looked promising, but it doesn’t work (gives same error that a local method using extends does - Type “string” has no member named “whatever”).
[quote=485605:@Norman Palardy]this IS extending a class though - windows are classes
But as stated you cannot extend some instances of a class one way and some in another
They’d have to actually be difference class types (which you could do as well and then extend those differently)
Interfaces should work for this as well but again you’d need different classes implementing different interfaces to make it work
I’m sure we could make this work the way you wanted[/quote]
I’m not sure you’re understanding my goal. I want to create STRING methods using the EXTENDS parameter option. So I am extending a STRING. But I want this method defined local to a Window, not in a Module. Right now Xojo requires any Method that uses the Extends parameter option to be in a Module.
If you know how to make the Interface paradigm work for this situation, I’m open. But I already tried it and the compiler still balks.
[quote=485609:@Jay Madren]I’m not sure you’re understanding my goal. I want to create STRING methods using the EXTENDS parameter option. So I am extending a STRING. But I want this method defined local to a Window, not in a Module. Right now Xojo requires any Method that uses the Extends parameter option to be in a Module.
If you know how to make the Interface paradigm work for this situation, I’m open. But I already tried it and the compiler still balks.[/quote]
OK there’s no way to extend a string locally within the context of JUST one window
The method would apply to ALL strings everywhere - you extend the entire string TYPE everywhere
Its why is says “EXTENDS name AS TYPE” the name is just a handy reference name for the type extension and the code IN that particular method
But you are extending the TYPE - not just one usage of it
Without knowing what it is more specifically you’re tying to do its hard to say how else this might be tackled
[quote=485654:@Markus Rauch]ahh, the idea is good and you would have methods only in a special scope. (it need a feature request)
your intend is similar to
var x as StringEx
a new class with base class string and u use it where u want.[/quote]
I logged an enhancement request a while back to implement type aliass. Maybe this would be another use for them.
Im not convinced this would be a good idea if it was possible. You want to do something with strings that is somehow specific to a certain window or a subclass of Window, but that window is never referenced it is a method defined for strings and it seems the window doesnt even feature as a parameter (if it did the extends method would already be officially specific to that window). Wouldnt it be much cleaner to define this as a method of that window like Julia suggested? That way you would render the connection to that window explicit. Thats my approach in similar cases.