Clipboard text reverts to last clipboard text?

  1. 3 weeks ago
    Edited 3 weeks ago

    I suck at explaining, I will delete the video once i have an answer, but can someone tell me what it is im doing wrong?

    im using the new clipboard item from docs

    Dim c As New Clipboard
    MsgBox Me.Text
    c.Text =me.Text
    c.Close

    except, its not working as intended.

    1. The inner window is a container, instantiated everytime the user double clicks a client name, so theres no past properties used, no global variables that would save last seen data........yet its somehow reverting back

    2. Me.text is the current text, so why revert?

    what am i looking for?

    watch video for what happens... 1 minute long

    https://youtu.be/Q6GdYsZhl_c

    @Tim P is the one who answered the question, Thank you for the time you spent helping a noob.

    If you embed a Container Control in a Canvas, or anywhere dynamically, and you are embedding that container - you have to close it before embedding another in the same place - or risk issues such as code firing multiple times.

    1. Create a global property as Container Control (Ie. ccx | ContainerControl)
    2. Embed, but be sure to assign the embedded container...
      Dim cc as new MyContainerControlName // Create a new instance of your Container Control
      ccx=cc // Assign your new instance to the ContainerControl Property
      cc.EmbedWithin(Canvas1,0,0,Canvas1.width,canvas1.Height) // Embed your Container Control

    3. Now you can call the close event from anywhere... even at the start of your method.

    ccx.close()

    * IF you place the code to close a container at the beginning of a method that loads a number of containers to the same canvas, remember that when the application first starts, no container exists and the close event will result in a NilObjectException.

    1. Create a global property as integer with a default of "0" (Ie. ccx_isopen | 0)
    2. Create an IF statement to check if any container has been created yet...
    If ccx_isopen=0 then
    ccx_isopen=1
    else
    ccx.close()
    end
  2. Emile S

    Nov 25 Europe (France, Strasbourg)

    Me.Text is not the current text. It is the text contained in the owning Control (the control where the code - above - reside).
    So, you store the Text of a Control (TextField/TextArea or Label ?), probably not what you want.

    Try instead c.Text = My_Control_Name.Text

    Your MsgBox returns the wrong text too.

    PS: the video is unavailable now (for me).

  3. try this - https://www.youtube.com/watch?v=Q6GdYsZhl_c

    I changed it to the control name - no affect. I was thinking maybe it was confused on the "me" value, but no. I'm still lost.

  4. Tim P

    Nov 25 Pre-Release Testers Rochester, NY

    You got two message boxes the second time. It's not reverting, it's happening more than once.

    If you try a third contact, do you get three message boxes?
    It could be that you're not closing the previous container, and the click is going through to the one no longer in view.

  5. Emile S

    Nov 25 Europe (France, Strasbourg)

    @RobertVanleeuwen try this - https://www.youtube.com/watch?v=Q6GdYsZhl_c

    Same. I am in Europe (France), this may be the reason. Check the region in you tube.

    Add a Break and watch (step) in the Debugger what happens (what is stored when its value is changed). It always helps.

    Using a MsgBox for debug is not always a good idea.

  6. Edited 3 weeks ago

    I checked youtube and the only box i didn't mark was that content never aired on US television - Distribution set to everywhere. Sorry, my loss I guess.

    @Tim P - Yes, 3 boxes appear.

    OK. So, I assume I'm not closing the container. But can someone explain why that matters here?

    So, I've been learning about how to dynamically draw and embed things into a canvas. It's allowed me to really make things flexible and less cluttered.

    this container is an embedded container. Not actually added to the window.

    dim cc as new containername
    canvas1.embed(cc)

    how do I programatically close the previous container when its not a global variable? I thought when you "Dim" something as "NEW" with the same name that it overwrites it....

    I'm guessing that it does overwrite it, but the canvas had it embedded before, so that means It's still embedded even though a new instance of the same name is embedded.

    ALL my containers are embedded by the name "cc"

    Yet that makes no sense to me. If I dim something as new with the same name and embed it - why wouldn't it just overwrite whatever was there to begin with?

    OK so maybe I don't need to "close" the cc... since it overwrites in program.

    Its the canvas I have to worry about right? how do I refresh the canvas as a clean slate?

  7. Emile S

    Nov 25 Europe (France, Strasbourg)

    Canvas1 = Nil ?

  8. @Emile S hahahaha, it couldn't be that simple

  9. for shits and giggles i tried it, nope lol

  10. As I put the cursor towards the top of the window, I see the resize column icon appear even though no list-box is there. So it is confirmed, the canvas always has whatever was embedded last on it. New embeds just overlap it. EVEN if what you embed on the canvas has the same name.

    so Why is this the case?
    and How do I clear the canvas?

  11. Tim P

    Nov 25 Pre-Release Testers Rochester, NY

    @Robert Vanleeuwen OK. So, I assume I'm not closing the container. But can someone explain why that matters here?

    You're using MouseDown, so since the control still exists underneath it's MouseDown event is still firing. You need to close the containers when they're not in view, you're wasting the memory for each container opened and then not closed.

    @Robert Vanleeuwen So, I've been learning about how to dynamically draw and embed things into a canvas. It's allowed me to really make things flexible and less cluttered.

    Nope. Stop right there. You need to embed the container into the Window, not a Canvas. http://docs.xojo.com/ContainerControl.EmbedWithin

    @Robert Vanleeuwen how do I programatically close the previous container when its not a global variable?

    Maintain a reference to the ContainerControl you're instancing and embedding. When the user navigates away from the detail view, close the container.

    @Robert Vanleeuwen I'm guessing that it does overwrite it, but the canvas had it embedded before

    Yes.

    @Robert Vanleeuwen so that means It's still embedded even though a new instance of the same name is embedded.

    Not so close. The instance that's embedded stays in scope, embedded into the window. The variable you'd used to do so is your last accessible reference to it. You should store that reference before replacing it. If you destroy the reference but not the embedded container you have to reacquire a reference to the container which isn't as easy as just keeping the reference in the first place.

    @Robert Vanleeuwen ALL my containers are embedded by the name "cc"

    You need better variable names if you want to understand the code in six months.

    @Robert Vanleeuwen Yet that makes no sense to me. If I dim something as new with the same name and embed it - why wouldn't it just overwrite whatever was there to begin with?

    When you embed the control into a window, you're adding the control to a window. What you're doing is not removing that control from the window. You're just missing a step.

    @Robert Vanleeuwen OK so maybe I don't need to "close" the cc... since it overwrites in program.

    Yes. You do. It does not get "overwritten" since you're embedding it.

    @Robert Vanleeuwen Its the canvas I have to worry about right?

    You need to remove the canvas, and embed properly into the window.

    @Robert Vanleeuwen how do I refresh the canvas as a clean slate?

    Canvas.Invalidate will cause another Paint event, but it's likely not what you actually want.

  12. Tim P

    Nov 25 Pre-Release Testers Rochester, NY
    Edited 3 weeks ago

    @RobertVanleeuwen How do I clear the canvas?

    Maintain a reference to the container as a property of the window. We're going to drop the canvas and embed correctly in this example.

    1. Create a property on the window, oOpenDetailView as ccMyDetailViewContainer.

    2. Store the instance of the container when you embed

    dim oNew as new ccMyDetailViewContainer
    oOpenDetailView = oNew
    oNew.EmbedWithin(self, 0, 0)

    3. When the user exits the detail view, close the container

    oOpenDetailView.Close
    oOpenDetailView = nil
  13. Tim P

    Nov 25 Pre-Release Testers Rochester, NY

    And frankly I'm surprised you're getting mouse events for a container embedded into a canvas. I would have expected embedding into a canvas to embed as an image, and not usable controls.

  14. Michel B

    Nov 25 Pre-Release Testers, Xojo Pro

    @Tim P And frankly I'm surprised you're getting mouse events for a container embedded into a canvas. I would have expected embedding into a canvas to embed as an image, and not usable controls.

    Well, using a canvas instead of a window has the advantage of enabling scrolling for the controls it contains.

  15. Tim P

    Nov 25 Pre-Release Testers Rochester, NY
    Edited 3 weeks ago

    @Michel B Well, using a canvas instead of a window has the advantage of enabling scrolling for the controls it contains.

    You can create scrolling for containers with just a pinch of extra effort. Adjusting the .Top of the container to be scrolled will do the trick. Whether you need a containing container or if it'll work on the window itself depends on the case. I would be curious if there are system level benefits to doing so.

  16. 2 weeks ago

    @Tim P is the one who answered the question, Thank you for the time you spent helping a noob.

    If you embed a Container Control in a Canvas, or anywhere dynamically, and you are embedding that container - you have to close it before embedding another in the same place - or risk issues such as code firing multiple times.

    1. Create a global property as Container Control (Ie. ccx | ContainerControl)
    2. Embed, but be sure to assign the embedded container...
      Dim cc as new MyContainerControlName // Create a new instance of your Container Control
      ccx=cc // Assign your new instance to the ContainerControl Property
      cc.EmbedWithin(Canvas1,0,0,Canvas1.width,canvas1.Height) // Embed your Container Control

    3. Now you can call the close event from anywhere... even at the start of your method.

    ccx.close()

    * IF you place the code to close a container at the beginning of a method that loads a number of containers to the same canvas, remember that when the application first starts, no container exists and the close event will result in a NilObjectException.

    1. Create a global property as integer with a default of "0" (Ie. ccx_isopen | 0)
    2. Create an IF statement to check if any container has been created yet...
    If ccx_isopen=0 then
    ccx_isopen=1
    else
    ccx.close()
    end

or Sign Up to reply!