Shoutbox

Pass object to a Wnd - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Pass object to a Wnd (/showthread.php?tid=64788)

Pass object to a Wnd by Shondoit on 08-11-2006 at 01:56 PM

I need some kind of method, to pass a custom Object to a PlusWnd, so I can use it again when the OnWindowEvent_CtrlClicked event fires....

i.e.

code:
function CreateWnd () {
   MyObject = new Object()
   MyObject.Name = "MyCustomObject"
   MyObject.Param = "ParamValue"
   var Wnd = MsgPlus.CreateWnd("windows.xml","settings")
   Wnd.CustomObject = MyObject
}
function OnSettingsEvent_CtrlClicked (Wnd, ControlId) {
   var MyObject = Wnd.CustomObject
   Debug.Trace(MyObject.Name)
}

This doesn't work, but I need something that has the same effect
RE: Pass object to a Wnd by -dt- on 08-11-2006 at 02:09 PM

What i do is create a hidden field on the window (in the xml) set that to a random ID, then store the object in a global array with that ID then when my event fires i read the ID from the Window and look it up in the array


RE: Pass object to a Wnd by Shondoit on 08-11-2006 at 02:12 PM

I already considered that, but I need the object itself, I want it to be a standalone object, not dependant of any arrays.

i.e. I have a .js with the object constructor, etc. And the Window Events, and a seperate .js with nothing more than 'obj = new MyObject()'

But thanks anyway


RE: Pass object to a Wnd by -dt- on 08-11-2006 at 02:16 PM

well Wnd isnt a normal object, neither is any of the Plus! objects  your only real way to do what you want is via what i said, which i dont see whats so wrong about it...


RE: Pass object to a Wnd by CookieRevised on 08-11-2006 at 06:10 PM

quote:
Originally posted by Shondoit
I need some kind of method, to pass a custom Object to a PlusWnd, so I can use it again when the OnWindowEvent_CtrlClicked event fires....

i.e.
code:
function CreateWnd () {
   MyObject = new Object()
   MyObject.Name = "MyCustomObject"
   MyObject.Param = "ParamValue"
   var Wnd = MsgPlus.CreateWnd("windows.xml","settings")
   Wnd.CustomObject = MyObject
}
function OnSettingsEvent_CtrlClicked (Wnd, ControlId) {
   var MyObject = Wnd.CustomObject
   Debug.Trace(MyObject.Name)
}

This doesn't work, but I need something that has the same effect


make and declare your object variable as a global variable, not as a local one:
code:
var MyObject = new Object();

function CreateWnd () {
   MyObject.Name = "MyCustomObject"
   MyObject.Param = "ParamValue"
   var Wnd = MsgPlus.CreateWnd("windows.xml","settings")
}
function OnSettingsEvent_CtrlClicked (Wnd, ControlId) {
   Debug.Trace(MyObject.Name)
}

RE: Pass object to a Wnd by Shondoit on 08-11-2006 at 10:58 PM

Well, thats what I do now, but when you do it like this, you need to now the name of the global object, and I don't want that, I want the object itself, so a user can name it whatever he likes...
But I don't think it's possible...

Perhaps Patchou can add Arguments support for Windows, so you can pass Parameters to a Window object, Patchou?... How 'bout it?


RE: Pass object to a Wnd by cooldude_i06 on 08-12-2006 at 05:40 AM

quote:
Originally posted by Shondoit
Well, thats what I do now, but when you do it like this, you need to now the name of the global object, and I don't want that, I want the object itself, so a user can name it whatever he likes...
But I don't think it's possible...

Perhaps Patchou can add Arguments support for Windows, so you can pass Parameters to a Window object, Patchou?... How 'bout it?

Yeah, I was also looking for a way to do this. It would be great if this could be extended for methods so you could add predefined methods for a Window object. Also it would be REALLY great if you could add methods to the Window class so that all windows will inherit that method(only in the current script ofcourse).
RE: RE: Pass object to a Wnd by CookieRevised on 08-13-2006 at 09:28 AM

quote:
Originally posted by cooldude_i06
quote:
Originally posted by Shondoit
Well, thats what I do now, but when you do it like this, you need to now the name of the global object, and I don't want that, I want the object itself, so a user can name it whatever he likes...
But I don't think it's possible...

Perhaps Patchou can add Arguments support for Windows, so you can pass Parameters to a Window object, Patchou?... How 'bout it?

Yeah, I was also looking for a way to do this. It would be great if this could be extended for methods so you could add predefined methods for a Window object. Also it would be REALLY great if you could add methods to the Window class so that all windows will inherit that method(only in the current script ofcourse).

What you ask for is something entirly different than what Shondoit asks for, if I read correctly...

As a matter of fact, I don't know exactly what Shondoit tries to do though as his request is a bit vague and as it is now, it seems a bit pointless. A detailed example (pseudo-code) would be helpfull, Shondoit...

What you, cooldude_i06, ask for is adding your own methods and functions to the special interfaces of Messenger Plus!. I also requested a method for this some while ago here.
RE: Pass object to a Wnd by Shondoit on 08-13-2006 at 12:46 PM

Well, actually, Cooldude wants the same as me, to pass parameters to the PlusWnd object...

Only he wants to pass a method, and I want to pass an Object

But your thread does the trick too, if it gets sorted out, that is


RE: Pass object to a Wnd by CookieRevised on 08-13-2006 at 06:10 PM

quote:
Originally posted by Shondoit
Well, actually, Cooldude wants the same as me, to pass parameters to the PlusWnd object...

Only he wants to pass a method, and I want to pass an Object
Which are totally two different things...

1) You don't pass methods, you add methods to existing objects.

A method is a function. It makes no sense to "pass" it to another object. "Passing" is a term used in context of variables and functions.

2) You don't pass stuff to windows, you pass stuff to functions.

A window isn't something which can perform stuff; it's a dead thing only visible on the screen. The functions supporting the window can perform stuff. Hence it makes no sense to pass something to "a window". You pass something to the function which controls the window.

And for this you don't need any fancy thing at all, just a global variable (which holds the object or whatever else) since those are the things which are "passed" to and used between functions.


So, the two things asked are in fact two different things (unless you or cooldude described something different than what you actually wanted).

;)

As for your own problem, Shondoit, a detailed (pseudo-) code example would be very helpfull in explaining to us what you actually are trying to accomplish. And maybe in that way I also can explain better that the thing you ask for and what cooldude asks for is actually totally different.

---

To add your own methods to objects, you use the prototype method. eg:
code:
String.prototype.trim = function() {
    return this.replace(/(^\s|\s$/g, "");
}
will add a trim method to the string object.

Note that the stuff which Plus! adds to JScript aren't objects but mainly interfaces, you can not use the protoype method to add your own methods to them...
RE: Pass object to a Wnd by Shondoit on 08-13-2006 at 06:25 PM

So maybe we phrased it a bit awkward...
But, a method/function is nothing more than an extended form of variable, so you can 'pass' methods

And when I mean, 'to pass an object/method to a window' I mean passing it to the CreateWnd function, wich would add it to the window, it's just how you phrase it

Objects, Methods and variables can all be properties of an object. When you create a constructor for your own custom object, you'll learn such things...

And as we stated before, we would like to 'pass' a 'variable/method/object' to the CreateWnd 'function' wich 'adds' them to the 'Window' so we can use them in the OnWindowCtrlClicked event, perhaps as callback, or perhaps as an settings object...
And we would like to make it standalone, instead of using a global var, especially for callbacks, this would be a great improvement


RE: Pass object to a Wnd by cooldude_i06 on 08-13-2006 at 06:44 PM

I think I know what Shondoit is asking for. He basically wants to give Window class custom properties.

Like:

code:
function createWindow(){
          var WndTest = MsgPlus.CreateWnd("interface.xml", "WndTest");
          WndTest.CustomProperty = "This is a custom property.";
}

function OnWndTestEvent_CtrlClicked(PlusWnd, ControlId){
         Debug.Trace(PlusWnd.CustomProperty);
}



RE: RE: Pass object to a Wnd by Shondoit on 08-13-2006 at 06:47 PM

Exactly, but you could also use:

code:
function createWindow(){
          var WndTest = MsgPlus.CreateWnd("interface.xml", "WndTest");
          WndTest.CustomProperty = function (x,y) { return x*y }
}

function OnWndTestEvent_CtrlClicked(PlusWnd, ControlId){
         Debug.Trace(PlusWnd.CustomProperty(2, 5));
}

Or
code:
function createWindow(){
          var WndTest = MsgPlus.CreateWnd("interface.xml", "WndTest");
          WndTest.CustomProperty = MyObject { x:3; y:4 }
}

function OnWndTestEvent_CtrlClicked(PlusWnd, ControlId){
         Debug.Trace(PlusWnd.CustomProperty.x);
}


RE: Pass object to a Wnd by cooldude_i06 on 08-13-2006 at 06:54 PM

Right, but Cookie asked that question and there doesnt seem to be a way to do it. Though I do agree that would make things a big easier (and tidy).


RE: RE: Pass object to a Wnd by CookieRevised on 08-13-2006 at 10:27 PM

quote:
Originally posted by Shondoit
So maybe we phrased it a bit awkward...
Indeed you did. And as such both of you requested a different thing (while you probably meant the same thing).

quote:
Originally posted by Shondoit
Objects, Methods and variables can all be properties of an object. When you create a constructor for your own custom object, you'll learn such things...
I did learned such things... see my previous request.