byRef to container controls

  1. ‹ Older
  2. 3 days ago

    Markus R

    Jun 30 Testers, Xojo Pro Europe / Germany / Lower Saxon...
    Edited 3 days ago

    if you have a= "Hello" or i = 123
    byval means you give a method the value "Hello" or 123
    byref means you give the method a or i
    objects as parameter did not have a value only the reference to it, its never byval.
    + xojo can not copy objects what would be similar as byval.
    if you need a object copy we need a self made method in the class.

  3. Norman P

    Jun 30 Testers, Xojo Pro outside admiring the sunshine,...

    A REFERENCE type ALWAYS allows you to change the data the reference points at
    In this case the data the reference points at is the data IN The array

    What you cannot do is change WHAT array is referred to (forget the data IN the array)

    In my first example the ONLY thing you can do is change the values IN the various positions in the array

    The second one actually returns a NEW array replacing the original

    Lets see if I can give an analogy
    The first is like being able to change the contents of the mailbox at the end of your driveway
    The mailbox remains the same - but the contents can change
    Thats the first example

    In the second I change the mailbox itself and so its very likely to contents also change

  4. Markus R

    Jun 30 Testers, Xojo Pro Europe / Germany / Lower Saxon...
    Edited 3 days ago

    simple explained - usually everything that is longer than a pointer/reference/integer (32/64bit)
    is or should given to a method as reference to save the time of copy data again and again.
    copy 4 bytes is faster than copy thousand bytes for a string can have.
    byval for a string is possible but not fast.
    byref for integer can have side effects to the calling method higher up.

  5. Norman P

    Jun 30 Testers, Xojo Pro outside admiring the sunshine,...
    Edited 3 days ago

    is an empty array larger than a pointer ?
    is the type a reference type or not ?
    those things matter

  6. Markus R

    Jun 30 Testers, Xojo Pro Europe / Germany / Lower Saxon...

    @Norman P is an empty array larger than a pointer ?
    is the type a reference type or not ?
    those things matter

    normal you give the method the array surroundings and not the content.
    empty or not you have a list and just this list struct use memory.
    so it make sense as parameter that is a reference to this 1 to XXXXXXXXXXX list.

  7. Eric W

    Jun 30 Testers, Xojo Pro
    Edited 3 days ago

    @Markus R objects as parameter did not have a value only the reference to it, its never byval.

    What is passed is a pointer to a data structure, which pointer can be passed byval or byref, as Xojo's reference states:

    By default, all arrays and objects are reference types that are passed ByVal. Because they are reference types, changes made to that array or object will be reflected in the calling method. This is no different than assigning an array or object to a second variable or property.

    I think I've got my head around what that means for the rare case when I want to assign a new object/array to a passed object/array as a whole.

  8. Norman P

    Jun 30 Testers, Xojo Pro outside admiring the sunshine,...

    following your logic

    Class Foo
    End Class
    
    dim f as new Foo
    

    Should F be passed to methods byref or not ?
    Understanding the difference between value and reference types and byval & byref and how these all play together is important
    I've seen some really fun bugs in user code from a very clear misunderstanding of how these work and what they mean

  9. Eric W

    Jun 30 Testers, Xojo Pro

    My understanding at present:

    If i pass f byval (the default) there's no risk of substituting foo as a whole, I can only operate foo according to its properties, methods etc.

    If I pass f byRef, I could swap in another foo complete, without other parts of my code referencing f knowing this happened. If foo represents sensitive info that could be kinda embarrassing.

    This is how I understand the concept.

  10. Norman P

    Jun 30 Testers, Xojo Pro outside admiring the sunshine,...

    Bingo !

  11. Eric W

    Jun 30 Testers, Xojo Pro

    Foo was here ;-)

  12. brian f

    Jun 30 Testers, Xojo Pro California

    @Eric W Foo was here ;-)

    Drops the mic and we hear "Foo has left the building"

  13. Norman P

    Jun 30 Testers, Xojo Pro outside admiring the sunshine,...

    foo yoo too :)

  14. Markus R

    Jun 30 Testers, Xojo Pro Europe / Germany / Lower Saxon...
    Edited 3 days ago

    i think the real problem start with the = assignment, sometimes it make a copy and sometimes not.

    this docu at ByVal is partly wrong.
    example

    When you pass parameters by value, it doesn't do this because in effect the parameter only represents a copy of the data itself.

    objects are not copied or represent a value direct.

    obj = no value (with the meaning of my data)
    obj.Value = value (as integer) property

    this should be named as ByRef = reference

    By default, all arrays and objects are reference types that are passed ByVal

    replaceing a ref parameter with a new object in the method is something what should be default.

    i know the behaviour of xojo but for me it seems this get messed up and then the guide was written.

  15. Clifford C

    Jun 30 Port Angeles, Washington

    Okay, guys now that you have all left for coffee and I'm byRefed out let's see if I can get back on track. Tim, you're up to speed on what I'm up to so you may know what's coming next. All is well creating 7 control containers, one for each day of the week. I'm now doing fine with all that excellent advice on passing an array(,) around and to the control containers. Values from the sliders are being captured, saved to the drive and back to the original array. As the last step, I need the open event of the sliders in the control containers to set themselves when they open to the values in the cloned array that was passed to the containers. The open events in the sliders are not going to cut it. The data is available since I can place the same code in the mouse enter event for the slider and it will set the slider after the control container is open. Before I make a workaround I'm sure someone might have the solution.

  16. Markus R

    Jun 30 Testers, Xojo Pro Europe / Germany / Lower Saxon...

    you could use the define event in a cc "RequestData" with a return value then use RaiseEvent at Open.
    the event come in the window where the cc are placed.
    without event return value you could also use Me.SetData in the event method.

    or if you open the new window with the 7 cc you could call a method .SetData

  17. Clifford C

    Jun 30 Port Angeles, Washington

    @Markus R you could use the define event in a cc "RequestData" with a return value then use RaiseEvent at Open.
    the event come in the window where the cc are placed.
    without event return value you could also use Me.SetData in the event method.
    Or if you open the new window with the 7 cc you could call a method .SetData

    For simplicity can .setdata be made to trigger a slider event. How does a .setdata method know when to fire to make the sliders respond or what would trigger the method?

  18. Tim H

    Jun 30 Portland, OR USA

    In the window's open event you read the data into your array and then call SetData on each container. SetData loads the values into each slider.

  19. Markus R

    Jun 30 Testers, Xojo Pro Europe / Germany / Lower Saxon...
    Edited 3 days ago

    setting a controls value have the side effect that it cause a change event.
    if you set a textfield.value = "abc" it raise a event. often unwanted.
    after you set the slider value his gui update self.

  20. Clifford C

    Jun 30 Port Angeles, Washington

    As usual, I have to beat things into submission before they will work but when I look back at the suggestions sent in I realize although I had tried several ways all I need to do was place the setData call in the action event of the day of the week selector buttons in the parent window and call the setData method in the containerConrol. So easy when you finally get there. And if you do not open one of the containerControls and its values are still set to 0 before saving it's not a problem, the change event in the slider never fires to update the clone array, no foul no harm. Thanks Markus and Tim.

  21. Markus R

    Jul 1 Testers, Xojo Pro Europe / Germany / Lower Saxon...

    ok, its difficult to well-advised just by text description. i think the possibilities gave you some puzzle pieces.

or Sign Up to reply!