Problem with TextArea.AppendText and Clipboard on Windows

I’m doing a sample project that I want it to run on Mac, Windows and Linux. I found 1 issue so I needed to use #If TargetMacOS and it works.

Now I found an issue with Windows, it looks like from this code:

Dim s As String Dim c As New Clipboard Self.logArea.Write("Running on: " + Extras.GetPlatform) Self.logArea.Write("1.- Using default EndOfLine") s = "1" + EndOfLine + "2" c.Text = s TextArea1.Text = s Self.logArea.Write("Original string as hex: " + EncodeHex(s,False)) Self.logArea.Write("Clipboard string as hex: " + EncodeHex(c.Text,False)) Self.logArea.Write("TextArea1.Text as hex: " + EncodeHex(TextArea1.Text,False))
Windows has a problem with EncodeHex(c.Text,False)

A fast solution is add ‘cb As String’ and ‘cb=c.Text’, changing EncodeHex(c.Text,False) with EncodeHex(cb,False) and it works. But I wanted to keep the original EncodeHex and check if the program is running on windows do the changes, like this:

#If TargetWin32 Then cb = c.Text Self.logArea.Write("Clipboard string as hex: " + EncodeHex(cb,False)) #Else Self.logArea.Write("Clipboard string as hex: " + EncodeHex(c.Text,False)) #EndIf
Mac and Linux worked but Windows had the same problem (empty result). After some tests, this worked:

cb = c.Text #If TargetWin32 Then Self.logArea.Write("Clipboard string as hex: " + EncodeHex(cb,False)) #Else Self.logArea.Write("Clipboard string as hex: " + EncodeHex(c.Text,False)) #EndIf

Why?

I expected to work with cb inside the #if

Note: the code is based on Robin’s sample from <https://xojo.com/issue/50385>

What if you use #if TargetWindows? I believe TargetWin32 is deprecated and will return false in 64-bit builds. (Haven’t tested that.)

TargetWin32 returns True on 64-bit. If you want to check the difference between 32 and 64 bit you need to use

#if Target32Bit #if Target64Bit

Thank you Kem, using TargetWindows work the same, but I found another problem:

Dim s,cb As String Dim c As New Clipboard Self.logArea.Write("Running on: " + Extras.GetPlatform) Self.logArea.Write("1.- Using default EndOfLine") s = "1" + EndOfLine + "2" c.Text = s TextArea1.Text = s cb = c.Text // <----- here it works Self.logArea.Write("Original string as hex: " + EncodeHex(s,False)) 'cb = c.Text // <----- doesn't work #If TargetWindows Then 'cb = c.Text // <----- doesn't work Self.logArea.Write("Clipboard string as hex: " + EncodeHex(cb,False)) #Else Self.logArea.Write("Clipboard string as hex: " + EncodeHex(c.Text,False)) #EndIf Self.logArea.Write("TextArea1.Text as hex: " + EncodeHex(TextArea1.Text,False))

I don’t know if something on Robin’s code clear the c.Text value but only on Windows (weird) or something else going on.

If I get this, you are assigning s to the clipboard, then reading it back out, yes? What’s the encoding on s? Perhaps it’s not really a valid representation of text and Windows doesn’t like that. (Just spitballing here.)

Yes, s to the clipboard and back again. I just do:

[quote]Dim s As String
s = “1” + EndOfLine + “2”[/quote]

I found out that with macOS the default EOL is chr(10) or 0A, but when using Xojo’s clipboard that value is changed to chr(13)/0D. And if you use mac’s Edit-Copy to use the system clipboard it works the opposite, that is, it changes chr(13)/0D to chr(10)/0A (at least from my tests). This is why I’m trying to build a sample project. There are other issues with EOL and in Windows too. Yes, I know that I should use ReplaceLineEndings to make sure that I get what I want, but I don’t think Xojo should change the values.

I did this test:

Dim s As String = "a" Dim c As New Clipboard c.Text = s Self.logArea.Write("c.Text: " + c.Text) Self.logArea.Write("c.Text: " + c.Text)
Result in Windows (Mac and LInux work ok):

c.Text: a c.Text:

I can’t find anything on the code as to why the clipboard (c.Text) is cleared after the first Self.logArea.Write.

Here is the Write code:

SysWrite(Text, eol) //Output to system log before doing anything potentially disrupting with the UI WinWrite(text, eol) //Output to the logging window (this may disrupt the UI, particularly with events)

SysWrite:

[code]Static sysText As String = “”

if sysLog then
sysText = sysText + Text
if eol then
System.DebugLog sysText
sysText = “”
end if
else
sysText = “”
end if[/code]

WinWrite:

if winLog then txaLog.AppendText text if eol then txaLog.AppendText EndOfLine end if 'ForceUpdate() end if

Any ideas?

Note: I know how to make it work, but I want to know why this issue and if this is a bug then report it.

Final test, at least remotely (have to test on Windows hardware), the problem is with TextArea.AppendText. A simple project with just TextArea1 and a Button with this code in Action:

Dim s As String = "a" Dim c As New Clipboard c.Text = s TextArea1.AppendText("c.Text: " + c.Text + EndOfLine) TextArea1.AppendText("c.Text: " + c.Text + EndOfLine)

Result on Windows:

c.Text: a c.Text:

<https://xojo.com/issue/53604>