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
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))
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.
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):
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)