Clipboard text disappears after .textavailable

Hi,

Odd thing happening and wondered if anyone else had seen this -

Background.
Simple windows only application that adds a trayitem to the windows tray that when clicked checks the clipboard content and if it finds text, checks it is a string of numbers and does a lookup in my db for a match and returns some data. The clipboard contents is from our softphone (it copies the incoming number to the clipboard).

All worked fine in testing and builds for the last few days on my machine and the builds on a couple of other users machines but sometime since the last build whenever I check the contents of the clipboard (e.g. “123456”) for text using:

Dim c As New Clipboard
c.TextAvailable
If c.TextAvailable Then

It returns true (as expected) but before I can do anything with it the clipboard is emptied. The time between returning true and emptying clipboard varies a bit as sometimes the next test (checking that it is a string of numbers) works and sometimes it doesn’t so I can’t reliably assign the clipboard to a variable after the check.

Really odd as this was working perfectly earlier in the day.

I have gone back to previous code that I know works (a couple of days before to be overly cautious and it was used in a build which still works fine) and the same thing now happens.

I have also tried on another machine (my home machine) with the XOJO IDE on but the same problem appears.

For reference I am using WindowsSystemTrayMBS as the tray item and the MouseLeftButtonDown event to trigger the check.

I am pulling my last strands of hair out trying to figure this one!

Any thoughts, suggestions on what to test etc?

Cheers,

Paul

Are you sure the softphone is not acting up ? From what you describe, the clipboard is set by it automatically.

First thing I would test is to stop it, and test the app with setting manually the clipboard from another app, ie. Notepad.

If everything checks out, then it is not your Xojo app but softphone. If somehow after placing text on the clipboard with Notepad your Xojo app loses it, then you want to check whatever in your code could modify the content of the clipboard.

Finally, would have you installed a new utility in your system that could disrupt the clipboard ?

Hi Michael,

Yes, I have been testing with manual clipboard loading and same thing, also tested on second machine with no soft phone and no clipboard managers etc.

I think I will create a clean app, no system tray code etc and see if it still happens.

Cheers

Paul

Why are you calling TextAvailable twice?

The middle line should not compile because the code is not using the value returned by c.TextAvailable.

Sorry, rushed code copy. Should read:

Dim c As New Clipboard
Dim s As String
If c.TextAvailable Then
    s = c.Text
End If

[quote=132686:@Paul Stevenson]Sorry, rushed code copy. Should read:

Dim c As New Clipboard Dim s As String If c.TextAvailable Then s = c.Text End If [/quote]

Just a hunch, but why not simply get c.text without testing TextAvailable, and if “” return. If as you describe the data disappears between the test and the fetch, go for the fetch directly. As far as I can see, it generates no error.

HI Michel and all,

I have been testing this for a few hours creating a blank app with no tray item, redoing the code from basics etc. and had tried not using textavailable and …

I am really sorry to all of you for wasting your time.

I think I was too close to the problem and should have stepped back :wink:

I just noticed that in testing 9 out of 10 times when I was manually loading the clipboard from a text file I was inadvertently copying a blank line as well so instead of:

“1234567” in the clipboard i had:

"
1234567"

So my code (and the when I looked at the variable in the IDE) only looked at the first (blank) line.

Now looking closer in the IDE using the magnifying glass symbol I can see the blank line.

Arrrgh that is about 4 hours of my life I will never get back!

So now I put the clipboard into a variable and remove the blank lines and it all works.

Panic over :slight_smile:

Thanks for all the suggestions and help.

Paul